Skip to content

Instantly share code, notes, and snippets.

@arnabsen1729
Created February 20, 2021 13:35
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 arnabsen1729/693cdda536e46bc27101726ac1f0434e to your computer and use it in GitHub Desktop.
Save arnabsen1729/693cdda536e46bc27101726ac1f0434e to your computer and use it in GitHub Desktop.
Docker Compose for MongoDB along with Mongo-Express with Root and Admin Auth, data persistent on docker.
version: <version>
services:
mongodb:
image: mongo
container_name: mongodb
environment:
- MONGO_INITDB_ROOT_USERNAME=<root>
- MONGO_INITDB_ROOT_PASSWORD=<root_pass>
volumes:
- mongodb-data:/data/db
networks:
- mongodb-network
ports:
- 27017:27017
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo 127.0.0.1:27017/test --quiet
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
mongo-express:
image: mongo-express
container_name: mongo-express
environment:
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_MONGODB_ADMINUSERNAME=<root>
- ME_CONFIG_MONGODB_ADMINPASSWORD=<root_pass>
- ME_CONFIG_BASICAUTH_USERNAME=<admin>
- ME_CONFIG_BASICAUTH_PASSWORD=<admin_pass>
volumes:
- mongodb-data
depends_on:
- mongodb
networks:
- mongodb-network
ports:
- 8081:8081
healthcheck:
test: wget --quiet --tries=3 --spider http://admin:admin123@127.0.0.1:8081 || exit 1
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
volumes:
mongodb-data:
name: mongodb-data
networks:
mongodb-network:
name: mongodb-network
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment