Chapter 5 · Lesson 10 of 10
Fix it

Fix a deploy that passes health checks but serves errors

A deploy that passes health checks but serves errors has a health check that tests less than real traffic needs, or traffic is routed somewhere other than the container you checked.

By the end you will

Test the real request path, find why a healthy deploy still errors, and fix the health check or the routing to match real traffic.

Time
20 min
Level
Intermediate
Check
4 questions
You need
  • An app behind a reverse proxy with a health endpoint
  • SSH access to the server

The deploy finished, the container reports healthy, the load balancer or Compose says everything is up, and yet visitors get 500 errors, blank pages or old content. The health check says yes while real traffic says no. That means the check tests something different from what users need, or traffic does not go where you think. Measure the real path first, then fix the check and the routing.

How it works#

A health check is a small test that runs on a schedule. In Docker, a HEALTHCHECK command runs inside the container, and the status becomes healthy when it exits 0. See Docker health checks. The check only knows what it tests. If it calls /health and that handler returns 200 without touching the database, then a dead database does not change the status. The container is healthy by definition and broken in practice.

The other half is routing. Users do not talk to the container you checked. They go through a reverse proxy, which forwards to an upstream address. If the proxy still points at the old container, a different port or a stale address, then the new, healthy container receives no traffic. The blog post health check passes, container dead shows a related case.

Step 1: Test the real path, not the health path#

From the server, call the public name the way a user does:

bash
curl -s -o /dev/null -w 'status=%{http_code} total=%{time_total}s\n' https://app.example.com/
curl -i https://app.example.com/some-real-page

Pick a page that uses the database or the full stack, such as a login or a list page, not the health route. Note the status and the body. If the real page fails while /health succeeds, the check is too shallow or routing is off. Continue to find which.

Step 2: Test the app directly#

Bypass the proxy and call the app on its internal address:

bash
curl -i http://127.0.0.1:3000/some-real-page

If you use a name-based proxy and the app checks the Host header, send it explicitly:

bash
curl -i -H 'Host: app.example.com' http://127.0.0.1:3000/some-real-page

Compare with Step 1:

  • Direct fails too: the app itself is broken, so the health check missed it (Steps 3 and 4).
  • Direct works, public fails: the problem is in the proxy or network (Step 5).

Step 3: Read what the health endpoint really does#

Open the code for the health route, or the HEALTHCHECK line, and look at what it tests:

bash
docker inspect --format '{{json .Config.Healthcheck}}' <container>
docker inspect --format '{{json .State.Health}}' <container>

The first shows the command, interval and timeout. The second shows the last results. A check such as curl -f http://localhost:3000/ against a static page, or exit 0, tests nothing real. Also check whether the status is only starting: a long start_period can hide a broken app, and an overly short one can mark a slow starter unhealthy.

Step 4: Read the app logs for the real failure#

bash
docker logs --tail 100 <container>

Look for connection errors to the database, missing environment variables, failed migrations, or a missing secret. A frequent cause after a deploy is a schema migration that did not run, so every request touching the new column fails while /health still passes. See read container logs for filters.

Step 5: Check where the proxy sends traffic#

bash
sudo nginx -T | grep -n -E 'proxy_pass|upstream|server_name'
docker ps --format 'table {{.Names}}\t{{.Ports}}\t{{.Status}}'

Confirm the upstream name and port match the new container. Typical causes of a wrong target:

  • The proxy resolved a container name at start and kept the old IP, so it needs a reload after the container is recreated.
  • A rolling or blue-green deploy left the proxy pointing at the old color. See blue-green vs rolling deploys.
  • Two containers share a network alias, and requests are split between old and new.
  • The proxy and the app are on different Docker networks, so the name resolves nowhere useful.

To see which instance answers, add a version or hostname in a response header and call the public URL several times.

Step 6: Make the health check meaningful#

Split it into two checks with different jobs:

  • Liveness: a cheap check that the process responds. Keep it shallow, so an outage of a dependency does not restart healthy apps.
  • Readiness: a deeper check that the instance can serve real work. It opens a connection to the database, runs a trivial query, and confirms migrations applied, with a short timeout.

An example readiness handler returns 200 only when its dependencies answer, and 503 with a short reason otherwise. In Docker, point the HEALTHCHECK at the readiness route, and in Compose make dependents wait on it:

yaml
services:
  app:
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:3000/ready"]
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 20s

Do not make the check call external third-party services you do not control, or their outage will mark you down. Keep the response small and free of secrets.

Step 7: Gate the deploy on the real path#

Add a smoke test after the deploy that calls a real page through the public URL, and roll back if it fails. See rollbacks and zero-downtime deploys. The proxy should only switch to the new version after readiness passes.

Check it worked#

bash
curl -s -o /dev/null -w 'status=%{http_code}\n' https://app.example.com/some-real-page
docker inspect --format '{{.State.Health.Status}}' <container>

The real page should return 200, and the health status should be healthy. To confirm the check is meaningful, briefly stop the database in a test environment and see readiness turn to failing.

Prevent it#

  • Test a real page in your deploy script, not only the health route.
  • Keep liveness shallow and readiness deep.
  • Alert on error rate from the proxy, not only on container health.

Edge cases and gotchas#

  • Caching: A CDN or proxy cache can serve a healthy-looking old page while the new app is broken. Test with a cache bypass.
  • Health route outside auth: Health routes often skip middleware that real routes need, such as sessions, so they pass while pages fail.
  • Start period: During it, failures are not counted, so a broken app can look fine for a while.
  • Per-instance checks: One healthy instance behind a balancer does not mean all are.
  • Host header: Apps that route by host reply differently to localhost, which is why Step 2 sends a Host header.
  • Timeouts: A check with a long timeout can pass slow, failing responses.

Troubleshooting#

SymptomLikely causeFix
Healthy, but pages return 500Shallow check, dependency brokenAdd a readiness check with the dependency
Public URL fails, direct curl worksProxy routes to old targetFix upstream, reload the proxy
Intermittent errors after deployOld and new instances both receive trafficRemove the old one, check aliases
Healthy right after start, then errorsMigration or warm-up not doneCheck readiness covers migrations
Container flaps unhealthyCheck too strict or timeout too shortTune interval, timeout, start_period
Old content after deployProxy or CDN cacheBypass or purge the cache

Quick reference#

bash
curl -s -o /dev/null -w 'status=%{http_code}\n' https://app.example.com/real-page
curl -i -H 'Host: app.example.com' http://127.0.0.1:3000/real-page
docker inspect --format '{{json .State.Health}}' <container>
docker logs --tail 100 <container>
sudo nginx -T | grep proxy_pass

Next#

Continue with Zero-downtime deploys.

Check what you learned4 questions
1What does a shallow health endpoint usually miss?
2Which question does a readiness check answer?
3After a deploy, curl to the container works but the public URL returns errors. What do you suspect?
4Why is a deep dependency check risky as a liveness check?

Frequently asked questions

Why does my app pass health checks but users still see errors?

The health check probably tests something shallow, such as a static route that always returns 200, while real requests need a database or cache. Or the proxy sends traffic to a different container than the one being checked.

What is the difference between liveness and readiness?

Liveness asks whether the process is alive and should be restarted if not. Readiness asks whether it can serve traffic right now and should receive requests. A process can be alive but not ready.

Should a health check test the database?

A readiness check should test dependencies the app cannot work without, with a short timeout. A liveness check should stay shallow, or a database outage will restart every app instance for no benefit.

How do I test what the proxy really sends to the app?

Run curl against the public name from the server, and use curl with a Host header against the app's internal address to compare. If they differ, the proxy routes somewhere else.

Sources

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios