Skip to content

Instantly share code, notes, and snippets.

@lahin31
Created September 25, 2022 08:20
Show Gist options
  • Save lahin31/fb29e84dc7ab06211af30c43b85604b9 to your computer and use it in GitHub Desktop.
Save lahin31/fb29e84dc7ab06211af30c43b85604b9 to your computer and use it in GitHub Desktop.
MongoDB inside Docker (docker-compose)
MONGO_ROOT_USER=root
MONGO_ROOT_PASSWORD=123456

Build with Docker Compose

docker-compose build

Run with Docker Compose

docker-compose up
version: "3.8"
services:
mongo:
image: mongo:5.0
container_name: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
restart: unless-stopped
ports:
- "27017:27017"
volumes:
- ./database/db:/data/db
mongo-express:
image: mongo-express
container_name: mongo-express
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_MONGODB_URL=mongodb://${MONGO_ROOT_USER}:${MONGO_ROOT_PASSWORD}@mongo:27017/?authSource=admin
- ME_CONFIG_BASICAUTH_USERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
links:
- mongo
restart: unless-stopped
ports:
- "8081:8081"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment