mongo-service/docker-compose.yml

75 lines
2.0 KiB
YAML

version: "3.8"
services:
mongodb:
image: mongo:6.0
container_name: mongodb
hostname: mongodb
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USERNAME:-admin}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD:-password}
volumes:
- mongodb_data:/data/db
- mongodb_config:/data/configdb
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
ports:
- "27017:27017" # Expose MongoDB port to external machines
command: ["--auth", "--bind_ip_all", "--replSet", "rs0"]
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/admin --quiet
interval: 10s
timeout: 5s
retries: 5
start_period: 40s
networks:
- mongo_network
ulimits:
nofile:
soft: 64000
hard: 64000
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "10"
mongo-express:
image: mongo-express:latest
container_name: mongo-express
hostname: mongo-express
restart: always
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_ROOT_USERNAME:-admin}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_ROOT_PASSWORD:-password}
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_USERNAME:-mexpress}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD:-mexpress}
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_SITE_BASEURL=/mongo-express
ports:
- "8081:8081" # Expose Mongo Express web interface to external machines
depends_on:
- mongodb
networks:
- mongo_network
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
networks:
mongo_network:
driver: bridge
# Adding explicit configuration to ensure proper DNS resolution
ipam:
config:
- subnet: 172.20.0.0/16
volumes:
mongodb_data:
driver: local
mongodb_config:
driver: local