Skip to content

Instantly share code, notes, and snippets.

@carlosesteven
Forked from devzer01/docker-compose.yml
Created September 23, 2020 04:59
Show Gist options
  • Save carlosesteven/5587d4b1397c26a849c6ce3d1f15ca54 to your computer and use it in GitHub Desktop.
Save carlosesteven/5587d4b1397c26a849c6ce3d1f15ca54 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