Browse Source

create docker-compose mongo replica

master
zeus 4 years ago
parent
commit
c9a45b8601
  1. 52
      docker-compose.yml

52
docker-compose.yml

@ -19,13 +19,13 @@ services:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
depends_on: depends_on:
- mongo1 - swarmlabmongo1
- mongo2 - swarmlabmongo2
- mongo3 - swarmlabmongo3
mongo1: swarmlabmongo1:
hostname: 'mongo1' hostname: 'swarmlabmongo1'
container_name: 'mongo1' container_name: 'swarmlabmongo1'
image: 'mongo:4.2' image: 'mongo:4.2'
restart: 'on-failure' restart: 'on-failure'
command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"]
@ -36,8 +36,8 @@ services:
networks: networks:
- netSwarmlabMongo - netSwarmlabMongo
volumes: volumes:
- mongoData1:/data/db - swarmlabmongoData1:/data/db
- mongoLog1:/var/log/mongodb - swarmlabmongoLog1:/var/log/mongodb
- ./.docker/mongodb/initdb.d/:/docker-entrypoint-initdb.d/ - ./.docker/mongodb/initdb.d/:/docker-entrypoint-initdb.d/
- ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/mongod.conf:/etc/mongod.conf
- ./.docker/mongodb/file.key:/auth/file.key - ./.docker/mongodb/file.key:/auth/file.key
@ -52,9 +52,9 @@ services:
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
mongo2: swarmlabmongo2:
hostname: 'mongo2' hostname: 'swarmlabmongo2'
container_name: 'mongo2' container_name: 'swarmlabmongo2'
image: 'mongo:4.2' image: 'mongo:4.2'
command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"]
restart: 'on-failure' restart: 'on-failure'
@ -65,8 +65,8 @@ services:
networks: networks:
- netSwarmlabMongo - netSwarmlabMongo
volumes: volumes:
- mongoData2:/data/db - swarmlabmongoData2:/data/db
- mongoLog2:/var/log/mongodb - swarmlabmongoLog2:/var/log/mongodb
- ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/mongod.conf:/etc/mongod.conf
- ./.docker/mongodb/file.key:/auth/file.key - ./.docker/mongodb/file.key:/auth/file.key
env_file: env_file:
@ -76,11 +76,11 @@ services:
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
depends_on: depends_on:
- mongo1 - swarmlabmongo1
mongo3: swarmlabmongo3:
hostname: 'mongo3' hostname: 'swarmlabmongo3'
container_name: 'mongo3' container_name: 'swarmlabmongo3'
image: 'mongo:4.2' image: 'mongo:4.2'
command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"] command: ["-f", "/etc/mongod.conf", "--keyFile", "/auth/file.key", "--replSet", "${MONGO_REPLICA_SET_NAME}", "--bind_ip_all"]
restart: 'on-failure' restart: 'on-failure'
@ -91,8 +91,8 @@ services:
networks: networks:
- netSwarmlabMongo - netSwarmlabMongo
volumes: volumes:
- mongoData3:/data/db - swarmlabmongoData3:/data/db
- mongoLog3:/var/log/mongodb - swarmlabmongoLog3:/var/log/mongodb
- ./.docker/mongodb/mongod.conf:/etc/mongod.conf - ./.docker/mongodb/mongod.conf:/etc/mongod.conf
- ./.docker/mongodb/file.key:/auth/file.key - ./.docker/mongodb/file.key:/auth/file.key
env_file: env_file:
@ -102,15 +102,15 @@ services:
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE} MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
depends_on: depends_on:
- mongo1 - swarmlabmongo1
volumes: volumes:
mongoData1: swarmlabmongoData1:
mongoData2: swarmlabmongoData2:
mongoData3: swarmlabmongoData3:
mongoLog1: swarmlabmongoLog1:
mongoLog2: swarmlabmongoLog2:
mongoLog3: swarmlabmongoLog3:
networks: networks:
netSwarmlabMongo: netSwarmlabMongo:

Loading…
Cancel
Save