DEV Community

Cover image for Why docker compose up -d Returning 0 Does Not Mean Your App Is Ready
hoagminh
hoagminh

Posted on Edited on

Why docker compose up -d Returning 0 Does Not Mean Your App Is Ready

Almost every VPS deployment script ends the same way:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Docker exits with code 0. Your CI pipeline turns green. Thirty seconds later, your monitoring alerts fire because the API container is stuck in a crash loop.

docker compose up -d only tells you that Docker started the containers. Even adding a single docker inspect check right afterward still lies—a crash-looping container alternates between restarting and running, so a poll that happens to land during the one second it is running reports a false success.

This is the problem behind deploy readiness and OOM diagnostics in Nitrobase.

Nitrobase has only recently launched and is still in Beta. Its readiness tracker is not a full APM or distributed tracing suite. Its job is narrower: watch a multi-container Compose stack over time so a deploy only turns green when every service actually stays up—and when it fails, tell you why instead of leaving you staring at a generic timeout.

One sample is never enough: require a stable window

When Nitrobase runs waitUntilHealthy, it polls docker inspect every 5s (APP_HEALTH_INTERVAL_MS), reading five fields per container: Compose service name, State.Status, State.ExitCode, RestartCount, and State.Health.Status.

Instead of declaring success on the first green poll, ReadinessTracker requires every service to remain ready with zero new restarts across at least 3 consecutive samples (APP_READY_STABLE_SAMPLES) spanning at least 20 seconds (APP_READY_STABLE_MS):

docker compose up -d
        |
        v
Poll docker inspect every 5s (ReadinessTracker)
        |
        +--> Boot phase: all services not up together yet
        |      └─ backstop limit: 3x restartLimit (default: 18)
        |
        +--> All services ready at once -> reset post-boot restart baseline
        |      ├─ any service hits restartLimit (default: 6) -> fail: APP_RESTART_LOOP
        |      ├─ same container unhealthy >= 60s & >= 3 polls -> fail: APP_UNHEALTHY
        |      └─ all ready, 0 new restarts for >= 20s & >= 3 polls -> container ready
        |
        v
Run HTTP health probe (throwaway curl container on proxy network)
        |
        v
Sample docker inspect one final time (catches crashes during probe)
Enter fullscreen mode Exit fullscreen mode

Two small classification rules prevent common Compose false positives:

  • One-shot containers (exited with code 0): Database migration or setup jobs are meant to exit cleanly, so exited(0) classifies as ready.
  • Non-zero exits (exited with code != 0): A container in the middle of being restarted by Docker can briefly appear as exited on one poll. Nitrobase only fails it as crashed if it stays exited with the same exit code and restart count for two consecutive samples.

Two-phase restart counting: why boot retries are not crash loops

On a fresh boot of a multi-container app, services that depend on a database routinely crash and restart a couple of times while Postgres or MySQL finishes initializing. Many upstream Compose files intentionally rely on restart: unless-stopped as their retry loop.

If you count every restart from second zero against a strict limit, healthy apps fail their first deploy. Worse, you cannot just track "was this individual service seen running once?", because a retrying web container is briefly running between failed database connection attempts.

Nitrobase solves this by splitting restart tracking into two phases:

Phase When it applies Failure threshold Why
Boot phase Before every service is ready simultaneously 3 × restartLimit (default 18) Allows legitimate dependency retries while still failing fast instead of waiting out the full 5-minute timeout
Post-boot phase Starts on the first sample where every service is ready at once (fresh RestartCounter baseline) restartLimit (default 6) Catches true crash loops once the stack has booted; fewer restarts still emit a job.warning naming the service (api (↻2))

If a container is recreated mid-wait and Docker resets its RestartCount to 0, RestartCounter automatically re-bases so deltas never go negative.

Give slow unhealthy containers a grace window

Docker marks a container unhealthy once its start_period plus retries have elapsed. On a small VPS with cold caches or heavy first-run migrations, a service can briefly flip unhealthy and recover on the very next healthcheck.

Rather than failing on the first unhealthy poll, ReadinessTracker tracks a per-service unhealthy streak bound to the container's current restart count:

  • A service only fails as APP_UNHEALTHY if the same container instance stays unhealthy continuously for at least 60 seconds (APP_UNHEALTHY_GRACE_MS) across at least 3 consecutive samples (APP_UNHEALTHY_SAMPLES).
  • If the container restarts or recovers, its unhealthy streak resets.
  • dead containers fail immediately.

Once the container stability window passes, Nitrobase runs an isolated HTTP probe from a throwaway curl container attached to the proxy network—and then runs one final docker inspect sample afterward, because a slow probe can take several seconds during which a fragile service might crash.

Catching silent OOM kills without falling for stale flags

When a container hits its memory limit, the Linux kernel terminates it with SIGKILL. Often the application never gets a chance to flush a single error line to logs—you just see exit code 137 and a restart loop.

Docker exposes State.OOMKilled, which looks straightforward until you run into two traps:

  1. State.OOMKilled is sticky. Docker sets it for the container's last exit and keeps it true until the container exits again or is recreated. If a container was OOM-killed three days ago and fails today because of a bad config change, naively reading State.OOMKilled blames memory when memory had nothing to do with it.
  2. Host vs. container OOM. If HostConfig.Memory is 0 (no container limit configured), the host ran out of RAM—telling the user to "raise the container's memory limit" is wrong advice.

Nitrobase's composeOomCommand inspects only container labels and state (never env vars or secrets) and prints the host's own clock first:

now<TAB>1795694400
api<TAB>true<TAB>536870912<TAB>2026-11-26T12:00:05.123456789Z
Enter fullscreen mode Exit fullscreen mode

parseOomKills then applies three filters:

  • Compares State.FinishedAt against now - withinSeconds using the host's own clock, eliminating clock skew between the control plane and the VPS while ignoring stale OOM kills from before the deploy started.
  • Ignores any kill where HostConfig.Memory <= 0 so container-limit hints only appear when a container limit actually caused the kill.
  • Pairs OOM checks with coded log failure signatures (FailureHints) without ever copying raw container logs (which may contain secrets) into the job event stream.

What deploy readiness checks still cannot prove

Container stability and a passing HTTP probe confirm that your processes booted cleanly and answered requests without crashing during the wait window. They cannot catch slow memory leaks that OOM three hours later, background worker deadlocks with no healthcheck, or subtle application-level data bugs. Those belong to continuous monitoring and app-level tests.

My checklist for reliable Compose deploy readiness

  • Never treat docker compose up -d exit code 0 or a single docker inspect poll as "ready"
  • Require a multi-sample stability window (running / healthy, zero new restarts) before declaring success
  • Separate boot-time dependency retries from post-boot crash loops so healthy first boots do not false-fail
  • Handle one-shot migration containers (exited(0)) and require two samples before failing non-zero exits
  • Re-sample container status after running HTTP probes
  • Filter State.OOMKilled by State.FinishedAt on the host's own clock and verify HostConfig.Memory > 0 before blaming a container limit

Exit code 0 means Docker accepted your request. Watching stability, restarts, health streaks, and OOM timestamps over time tells you whether your app actually survived startup.

Nitrobase source code: https://github.com/AydenGroup/nitrobase

Top comments (0)