Hello my mongo health check is failing below is my docker-compose file
version: "2.4"
services:
production-api:
build: .
environment:
- MONGO_URI=mongodb://mongodb:27017/productiondb
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- mongodb
# condition: service_healthy
mongodb:
image: mongo
ports:
- "27017:27017"
# healthcheck:
# test: echo 'db.runCommand("ping").ok' | mongo mongo:27017/productiondb --quiet 1
# interval: 10s
# timeout: 10s
# retries: 5
And is there any way to pass MONGO_URI to health check as a variable?
you're healthcheck should look like this:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/productiondb --quiet
mongo
doesn't exist inside the mongodb
container unless you specify hostname: mongo
in your compose file or just simply use localhost
which is more common, when doing healthchecks1
after --quiet
seems to be a typo which leads to [main] file [1] doesn't exist
https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-quiet see also:
You can pass MONGO_URI
to the healthcheck, by specifying it a second time:
mongodb:
..
environment:
- MONGO_URI=mongodb://mongodb:27017/productiondb
If you want to use one value for both, create an env_file
and use it via:
env_file:
- mongo.env # wich contains `MONGO_URI=mongodb://..`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.