docker-compose status returns unhealthy while endpoint returns healthy
See original GitHub issuedocker-compose ps
returns:
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------------------------
apps_shynet-db_1 docker-entrypoint.sh postgres Up 5432/tcp
apps_shynet_1 ./entrypoint.sh Up (unhealthy) 0.0.0.0:49654->8080/tcp,:::49654->8080/tcp
curl 172.25.0.3:8080/healthz/?format=json
(Where the IP points to the container) returns:
HTTP/1.1 200 OK
Server: gunicorn
Date: Thu, 13 Jan 2022 06:54:20 GMT
Connection: close
Content-Type: application/json
Expires: Thu, 13 Jan 2022 06:54:20 GMT
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
X-Frame-Options: DENY
Content-Length: 67
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
{"Cache backend: default": "working", "DatabaseBackend": "working"}
Looks like unintended behaviour.
This prevents strict ingress controllers like Traefik from functioning because it would filter out anything that fails the health-check.
More context:
startup logs (no warnings):
shynet_1 | Launching Shynet web server...
shynet_1 | [2021-12-30 13:55:35 +0000] [1] [INFO] Starting gunicorn 20.1.0
shynet_1 | [2021-12-30 13:55:35 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
shynet_1 | [2021-12-30 13:55:35 +0000] [1] [INFO] Using worker: sync
shynet_1 | [2021-12-30 13:55:35 +0000] [9] [INFO] Booting worker with pid: 9
traefik | time="2021-12-30T13:55:38Z" level=debug msg="Filtering unhealthy or starting container" providerName=docker container=shynet-apps-d407b653cda6c44be6193efe8da6c8fd44a6e8c798957e44d2a20ea3068f75dc
compose file
version: '3'
services:
traefik:
restart: always
image: traefik:2.5
container_name: traefik
command:
- --entrypoints.web.address=:80
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --log=true
- --log.level=DEBUG
ports:
- 80:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
shynet:
image: shynet:docker-fix
restart: unless-stopped
ports:
- '8080'
environment:
- DB_HOST=shynet-db
- DB_NAME=shynet
- DB_USER=shynet
- DB_PASSWORD=shynet
- DJANGO_SECRET_KEY=shynet
- TIME_ZONE=Africa/Nairobi
labels:
- traefik.enable=true
- traefik.port=8080
# dns entry for api.local -> 127.0.0.1
- traefik.http.routers.analytics.rule=Host(`api.local`)
depends_on:
- shynet-db
- traefik
shynet-db:
image: postgres:13-alpine
restart: always
environment:
- POSTGRES_DB=shynet
- POSTGRES_USER=shynet
- POSTGRES_PASSWORD=shynet
volumes:
- ./shynet_db:/var/lib/postgresql/data
As a temporary fix, I am completely removing the HEALTHCHECK
from the Dockerfile and rebuilding the image, that works in my case when using Traefik.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Can docker-compose ps show health status? #5525 - GitHub
@AnthonyMastrean Looks like inspect API endpoint does return Health status if "healthcheck" is specified for the container.
Read more >Docker health check always returning as unhealthy
I wouldn't say it is unhealthy as the screenshot shows "message": "healthy" . It probably has something to do with your docker inspect...
Read more >Unhealthy container does not restart - Compose
Its because the healthchecks is for docker swarm, if you're running it just, native docker, nothing will happend if a container gues unhealthy....
Read more >Docker: A Health-Check Story!. Background | by Payam Mousavi
Docker runs those commands and checks the returned status code and ... Docker the container has a problem and is unhealthy at this...
Read more >Using the Docker Healthcheck Command - Couchbase
starting – Initial status when the container is still starting · healthy – If the command succeeds then the container is healthy ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for making this fix!
I think I was seeing the same issue… this happens when
ALLOWED_HOSTS
is either unset or still set to the default*
:So I’m assuming the new health check is not yet working for that specific case of
ALLOWED_HOSTS
being set to*
. After settingALLOWED_HOSTS
to a set of host names the health check was working and my container was starting as expected again.