Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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