services: mongo: image: 'mongo:5' ports: - '27017' expose: - '27017' hostname: 'mongo' container_name: 'mongodb' command: ['--replSet', 'rs0' ] healthcheck: test: "mongo --host mongo:27017 --eval 'rs.status()' | grep 'health.*1,'" interval: 5s timeout: 3s retries: 20 mongosetup: image: 'mongo:5' depends_on: - mongo restart: "no" entrypoint: [ "bash", "-c", "sleep 5 && mongo --host mongo:27017 --eval 'rs.initiate({ _id: \"rs0\", members: [ { _id: 0, host: \"mongo:27017\" } ] })'" ]