version: '3.8' services: # setup MongoDB cluster for production mongo-replica-setup: container_name: mongo-setup image: 'mongo:4.2' restart: on-failure networks: - netSwarmlabMongo volumes: - ./.docker/mongodb/scripts/mongosetup.sh:/scripts/mongosetup.sh # entrypoint: ["bash"] entrypoint: ["bash", "/scripts/mongosetup.sh" ] env_file: - .env environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} depends_on: - mongo1 - mongo2 - mongo3 mongo1: hostname: 'mongo1' container_name: 'mongo1' image: 'mongo:4.2' restart: 'on-failure' command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] expose: - 27017 ports: - 30001:27017 networks: - netSwarmlabMongo volumes: - mongoData1:/data/db - mongoLog1:/var/log/mongodb - ./.docker/mongodb/initdb.d/:/docker-entrypoint-initdb.d/ - ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/file.key:/auth/file.key healthcheck: test: test $$(echo "rs.status().ok" | mongo -u $${MONGO_INITDB_ROOT_USERNAME} -p $${MONGO_INITDB_ROOT_PASSWORD} --quiet) -eq 1 interval: 30s start_period: 60s env_file: - .env environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} mongo2: hostname: 'mongo2' container_name: 'mongo2' image: 'mongo:4.2' command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] restart: 'on-failure' expose: - 27017 ports: - 30002:27017 networks: - netSwarmlabMongo volumes: - mongoData2:/data/db - mongoLog2:/var/log/mongodb - ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/file.key:/auth/file.key env_file: - .env environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} depends_on: - mongo1 mongo3: hostname: 'mongo3' container_name: 'mongo3' image: 'mongo:4.2' command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] restart: 'on-failure' expose: - 27017 ports: - 30003:27017 networks: - netSwarmlabMongo volumes: - mongoData3:/data/db - mongoLog3:/var/log/mongodb - ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/file.key:/auth/file.key env_file: - .env environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} depends_on: - mongo1 volumes: mongoData1: mongoData2: mongoData3: mongoLog1: mongoLog2: mongoLog3: networks: netSwarmlabMongo: