docker compose 部署MongoDB单节点
version : '2'
services :
mongodb :
image : docker.io/bitnami/mongodb: 6.0
ports :
- "27017:27017"
volumes :
- 'mongodb_data:/bitnami/mongodb'
volumes :
mongodb_data :
driver : local
docker compose 部署MongoDB集群
version : '2'
services :
mongodb-primary :
image : docker.io/bitnami/mongodb: 6.0
environment :
- MONGODB_ADVERTISED_HOSTNAME=mongodb- primary
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
volumes :
- 'mongodb_master_data:/bitnami/mongodb'
mongodb-secondary :
image : docker.io/bitnami/mongodb: 6.0
depends_on :
- mongodb- primary
environment :
- MONGODB_ADVERTISED_HOSTNAME=mongodb- secondary
- MONGODB_REPLICA_SET_MODE=secondary
- MONGODB_INITIAL_PRIMARY_HOST=mongodb- primary
- MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
mongodb-arbiter :
image : docker.io/bitnami/mongodb: 6.0
depends_on :
- mongodb- primary
environment :
- MONGODB_ADVERTISED_HOSTNAME=mongodb- arbiter
- MONGODB_REPLICA_SET_MODE=arbiter
- MONGODB_INITIAL_PRIMARY_HOST=mongodb- primary
- MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=password123
- MONGODB_REPLICA_SET_KEY=replicasetkey123
volumes :
mongodb_master_data :
driver : local
环境变量参数
MONGODB_EXTRA_FLAGS : mongd命令启动时,追加在命令后的参数, 没有默认值。ALLOW_EMPTY_PASSWORD :允许启动时密码为空。MONGODB_CLIENT_EXTRA_FLAGS : 要附加到用于连接(本地或远程)“mongod”守护进程的“mongo”命令的标志。无默认值。