Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Forked from devzer01/docker-compose.yml
Created October 22, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuelnk/1dce0abb1de548bd4992fa467ad588ff to your computer and use it in GitHub Desktop.
Save emmanuelnk/1dce0abb1de548bd4992fa467ad588ff to your computer and use it in GitHub Desktop.
docker-compose mongodb
version: '3'
services:
database:
image: 'mongo'
container_name: 'my-mongo-container' # give your contatner a name
environment:
- MONGO_INITDB_DATABASE=your-database-name # database name you want to make
- MONGO_INITDB_ROOT_USERNAME=my-container-root-username # set your container root username
- MONGO_INITDB_ROOT_PASSWORD=secret # set your contatner root password
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ./mongo-volume:/data/db
ports:
- '27017-27019:27017-27019'
# ... other configs ...
db.createUser(
{
user: "YourUsername",
pwd: "“YourPasswordHere",
roles: [
{
role: "readWrite",
db: "your-database-name"
}
]
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment