Skip to content

Instantly share code, notes, and snippets.

@devzer01
Last active December 1, 2021 14:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save devzer01/0ebcdb6a4f5b6858ec30dcc7b767a538 to your computer and use it in GitHub Desktop.
Save devzer01/0ebcdb6a4f5b6858ec30dcc7b767a538 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