$ sudo echo "127.0.0.1 mongo1\n127.0.0.1 mongo2\n127.0.0.1 mongo3" >> /etc/hosts
docker-componse.yml
version: "3.7"
services:
mongo1:
container_name: mongo1
image: mongo
ports:
- 27017:27017
restart: always
entrypoint: [ "mongod","--port","27017", "--bind_ip_all", "--replSet", "rs0" ]
mongo2:
container_name: mongo2
image: mongo
ports:
- 27027:27027
restart: always
entrypoint: [ "mongod","--port","27027", "--bind_ip_all", "--replSet", "rs0" ]
mongo3:
container_name: mongo3
image: mongo
ports:
- 27037:27037
restart: always
entrypoint: [ "mongod","--port","27037", "--bind_ip_all", "--replSet", "rs0" ]
healthcheck:
test: ["CMD","mongo","--host","mongo1","--port","27017", "--eval", 'rs.initiate( { _id : "rs0",members: [{ _id: 0, host: "mongo1:27017" },{ _id: 1, host: "mongo2:27027" },{ _id: 2, host: "mongo3:27037" } ]})']
interval: 15s
timeout: 10s
retries: 3
start_period: 10s
$ docker-compose up