Skip to content

Instantly share code, notes, and snippets.

@ferromir
Created February 20, 2024 12:53
Show Gist options
  • Save ferromir/1f094b402a577cff0e408bdce2c34284 to your computer and use it in GitHub Desktop.
Save ferromir/1f094b402a577cff0e408bdce2c34284 to your computer and use it in GitHub Desktop.
Docker compose for single node MongoDB replica set
version: "3.8"
services:
mongo:
image: mongo:5.0.11
container_name: "mongo"
command: --replSet rs
volumes:
- mongo-data:/data/db
ports:
- "27017:27017"
mem_limit: 5000m
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017 --quiet
interval: 2s
timeout: 10s
retries: 10
mongo-rs-init:
container_name: mongo-rs-init
image: mongo:5.0.11
restart: on-failure
depends_on:
mongo:
condition: service_healthy
command: >
mongosh mongodb://mongo --eval 'rs.initiate({ _id: "rs", members: [ { _id: 0, host: "localhost:27017" } ]})'
volumes:
mongo-data:
driver: local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment