docker _compose_MongoDB_0">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_18">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=replicasetkey123volumes : - 'mongodb _master_data:/bitnami/mongodb ' mongodb -secondary: image : docker .io/bitnami/mongodb : 6.0 depends_on : - mongodb - primaryenvironment : - 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=replicasetkey123mongodb -arbiter: image : docker .io/bitnami/mongodb : 6.0 depends_on : - mongodb - primaryenvironment : - 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=replicasetkey123volumes : mongodb _master_data: driver : local
环境变量参数
MONGODB_EXTRA_FLAGS : mongd命令启动时,追加在命令后的参数, 没有默认值。ALLOW_EMPTY_PASSWORD :允许启动时密码为空。MONGODB_CLIENT_EXTRA_FLAGS : 要附加到用于连接(本地或远程)“mongod”守护进程的“mongo”命令的标志。无默认值。