主机A
[root@mysql_master zhxf]# cat docker-compose.yml version: '3' services: mongo_rs1: image: mongo:3.4.4 container_name: mongo_rs1 volumes: - /zhxf/mongo_rs1/:/mongodb command: mongod --logpath /mongodb/mongo.log --logappend --dbpath /mongodb --master --slave --source 172.16.160.92:27017 --autoresync ulimits: nproc: 65535 hostname: mongo_rs1 restart: always ports: - "27017:27017" [root@mysql_master zhxf]#
主机B
[root@mysql_slave1 zhxf]# cat docker-compose.yml version: '3' services: mongo_rs2: image: mongo:3.4.4 container_name: mongo_rs2 volumes: - /zhxf/mongo_rs2/:/mongodb command: mongod --logpath /mongodb/mongo.log --logappend --dbpath /mongodb --master --slave --source 172.16.160.91:27017 --autoresync ulimits: nproc: 65535 hostname: mongo_rs2 restart: always ports: - "27017:27017" [root@mysql_slave1 zhxf]#