Last active
September 6, 2023 20:32
-
-
Save medfreeman/9fe30c43706420c6df19a14ac98a2458 to your computer and use it in GitHub Desktop.
docker / mongo replicaSet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
dockerhost: | |
image: qoomon/docker-host | |
hostname: '${MONGO_HOST:?err}' | |
container_name: '${MONGO_HOST:?err}' | |
cap_add: ['NET_ADMIN', 'NET_RAW'] | |
restart: on-failure | |
mongodb-primary: | |
depends_on: [dockerhost] | |
hostname: mongodb-primary | |
build: | |
context: . | |
cache_from: | |
- 'mongo:${MONGO_VERSION:?err}' | |
- imz-mongodb | |
dockerfile: Dockerfile | |
args: | |
- MONGO_VERSION=${MONGO_VERSION:?err} | |
image: imz-mongodb | |
expose: | |
- 27017 | |
ports: | |
- 27017:27017 | |
restart: always | |
command: '--bind_ip 0.0.0.0 --setParameter disableJavaScriptJIT=false --keyFile /data/keyfile/keyfile --replSet ${MONGO_REPLICA_SET:?err}' | |
environment: | |
MONGO_INITDB_ROOT_USERNAME: '${MONGO_ROOT_USERNAME:?err}' | |
MONGO_INITDB_ROOT_PASSWORD: '${MONGO_ROOT_PASSWORD:?err}' | |
MONGO_INITDB_DATABASE: '${MONGO_AUTH_DATABASE:?err}' | |
volumes: | |
- /data/keyfile/ | |
- ./storage:/data | |
mongodb-secondary: | |
depends_on: [dockerhost] | |
hostname: mongodb-secondary | |
build: | |
context: . | |
cache_from: | |
- 'mongo:${MONGO_VERSION:?err}' | |
- imz-mongodb | |
dockerfile: Dockerfile | |
args: | |
- MONGO_VERSION=${MONGO_VERSION:?err} | |
image: imz-mongodb | |
expose: | |
- 27018 | |
ports: | |
- 27018:27018 | |
restart: always | |
command: '--bind_ip 0.0.0.0 --port 27018 --setParameter disableJavaScriptJIT=false --keyFile /data/keyfile/keyfile --replSet ${MONGO_REPLICA_SET:?err}' | |
mongodb-arbiter: | |
depends_on: [dockerhost] | |
hostname: mongodb-arbiter | |
build: | |
context: . | |
cache_from: | |
- 'mongo:${MONGO_VERSION:?err}' | |
- imz-mongodb | |
dockerfile: Dockerfile | |
args: | |
- MONGO_VERSION=${MONGO_VERSION:?err} | |
image: imz-mongodb | |
expose: | |
- 27019 | |
ports: | |
- 27019:27019 | |
restart: always | |
command: '--bind_ip 0.0.0.0 --port 27019 --setParameter disableJavaScriptJIT=false --keyFile /data/keyfile/keyfile --replSet ${MONGO_REPLICA_SET:?err}' | |
mongodb-init_script: | |
depends_on: [mongodb-primary, mongodb-secondary, mongodb-arbiter] | |
image: 'mongo:${MONGO_VERSION:?err}' | |
restart: 'no' | |
entrypoint: | |
- /bin/bash | |
- -c | |
- | | |
sleep 10; \ | |
mongo --host ${MONGO_HOST:?err} --username ${MONGO_ROOT_USERNAME:?err} --password ${MONGO_ROOT_PASSWORD:?err} --authenticationDatabase ${MONGO_AUTH_DATABASE:?err} \ | |
--eval 'rs.initiate({ _id: "${MONGO_REPLICA_SET:?err}", members: [ { _id: 0, host: "${MONGO_HOST:?err}:27017" }, { _id: 1, host: "${MONGO_HOST:?err}:27018" }, { _id: 2, host: "${MONGO_HOST:?err}:27019", arbiterOnly: true } ] });' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG MONGO_VERSION | |
FROM mongo:${MONGO_VERSION} | |
RUN mkdir -p /data/keyfile | |
RUN openssl rand -base64 741 > /data/keyfile/keyfile | |
RUN chown -R mongodb:mongodb /data/keyfile | |
RUN chmod 600 /data/keyfile/keyfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then make sure your hostname is resolvable on you host / client machines.