version: "3.1" # Our containers services: # Temporary container used to initialize the replica set mongo-setup: container_name: mongo-setup image: mongo restart: on-failure networks: default: volumes: - ./scripts:/scripts # Ensure the './scripts' directory exists with the 'setupReplicaSet.sh' file entrypoint: ["/scripts/setupReplicaSet.sh"] # Call the 'setupReplicaSet.sh' script on container init depends_on: # Wait for the 3 DB containers to spin up first - mongo1 - mongo2 - mongo3 mongo1: hostname: mongo1 # You need to map this hostname to 127.0.0.1 in your /etc/hosts file container_name: mongo1 image: mongo expose: - 27017 ports: - 27017:27017 networks: default: restart: always volumes: - ./mongo-volumes/mongo1/data/db:/data/db # Create a volume to persist data entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false", "--port", "27017"] mongo2: hostname: mongo2 # You need to map this hostname to 127.0.0.1 in your /etc/hosts file container_name: mongo2 image: mongo expose: - 27018 ports: - 27018:27018 networks: default: restart: always volumes: - ./mongo-volumes/mongo2/data/db:/data/db # Create a volume to persist data entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false", "--port", "27018"] mongo3: hostname: mongo3 # You need to map this hostname to 127.0.0.1 in your /etc/hosts file container_name: mongo3 image: mongo expose: - 27019 ports: - 27019:27019 networks: default: restart: always volumes: - ./mongo-volumes/mongo3/data/db:/data/db # Create a volume to persist data entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false", "--port", "27019"]