简体   繁体   中英

docker-compose mongo healthcheck failing

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM