docker跑mongo主从复制
这是docker-compose.yml
version: '3.1'
services:
mongo:
container_name: 'mongo'
hostname: 'mongo'
image: mongo
restart: always
volumes:
- ./root/mongo:/root/mongo
- ./root/mongo/db:/data/db
networks:
- web
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: 'root'
MONGO_INITDB_ROOT_PASSWORD: 'e7b9e773f9c00abdaf8bb97babe352ae'
entrypoint:
- bash
- -c
- |
cp /root/mongo/replica.key /data/replica.key
chmod 400 /data/replica.key
chown 999:999 /data/replica.key
exec docker-entrypoint.sh $$@
command: "mongod --bind_ip_all --replSet rs0 --keyFile /data/replica.key"
mongo-express:
container_name: 'mongo-express'
image: mongo-express
restart: always
networks:
- web
ports:
- 8081:8081
environment:
ME_CONFIG_BASICAUTH_USERNAME: 'admin'
ME_CONFIG_BASICAUTH_PASSWORD: 'admin'
ME_CONFIG_MONGODB_URL: 'mongodb://root:e7b9e773f9c00abdaf8bb97babe352ae@mongo:27017'
networks:
web:
external: true
标签:主从复制,mongo,data,replica,key,docker,root
From: https://www.cnblogs.com/xiangxisheng/p/17841619.html