Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JonathanLoscalzo/a9099071fcf2d462d89b48bab8ac95d7 to your computer and use it in GitHub Desktop.
Save JonathanLoscalzo/a9099071fcf2d462d89b48bab8ac95d7 to your computer and use it in GitHub Desktop.
Initializing mongo db in docker-compose with init script
version: '3.8'
services:
# Database - Mongo DB
mongo:
image: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: helpdev
MONGO_INITDB_ROOT_PASSWORD: 123456
ports:
- "27017:27017"
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
# Database Manager
mongo-express:
image: mongo-express
ports:
- 8099:8081
depends_on:
- mongo
environment:
ME_CONFIG_BASICAUTH_USERNAME: express
ME_CONFIG_BASICAUTH_PASSWORD: 123456
ME_CONFIG_MONGODB_PORT: 27017
ME_CONFIG_MONGODB_ADMINUSERNAME: helpdev
ME_CONFIG_MONGODB_ADMINPASSWORD: 123456
links:
- mongo
db = db.getSiblingDB('sample_db');
db.createCollection('sample_collection');
db.sample_collection.insertMany([
{
org: 'helpdev',
filter: 'EVENT_A',
addrs: 'http://rest_client_1:8080/wh'
},
{
org: 'helpdev',
filter: 'EVENT_B',
addrs: 'http://rest_client_2:8081/wh'
},
{
org: 'github',
filter: 'EVENT_C',
addrs: 'http://rest_client_3:8082/wh'
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment