SnowOps Night Shift

Why does my Docker container exit immediately after I change its config?

A container stops when its main process exits, and a server that rejects its configuration exits at start. docker ps -a shows the container as Exited with a code, and docker logs shows the last thing the process printed, which usually names the bad line. Restarting reads the same config and fails the same way. In this incident nginx exited with code 1 on a directive it does not have, added by a config change.

What it looks like

  • docker ps -a shows the container as Exited (1) a few seconds after it started.
  • Nothing answers on the published port, not even an error page.
  • A restart brings it up for a moment and it exits again.
  • The trouble began right after a config change.

Commands that find the cause

  1. docker logs --tail 5 storefront

    The last lines the container printed before it stopped. For a server that exits at start, the reason is usually the final line: read it first.

  2. cat default.conf

    The site config that is copied into the container. Compare it with what the log complains about: the line number in the error points into this file.

  3. docker ps -a

    Lists every container, running or not. Read STATUS: Up means running, Exited (n) means it stopped with exit code n, Restarting means Docker keeps trying. PORTS shows host to container mappings.

  4. docker inspect -f '{{.State.Status}} exit={{.State.ExitCode}}' storefront

    The container's state and exit code straight from Docker. 0 is a clean stop, 1 is the program giving up on its own, 137 is a kill from outside.

What the evidence looked like

Recorded on a real system when this incident was captured for the game.

$ docker logs --tail 5 storefront
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2026/11/29 12:47:04 [emerg] 1#1: unknown directive "gzip_level" in /etc/nginx/conf.d/default.conf:4
nginx: [emerg] unknown directive "gzip_level" in /etc/nginx/conf.d/default.conf:4

Root cause

A config change added a directive nginx does not support, so nginx exited at start; removing it restored the storefront.

The fix

Remove the bad line from the config, copy it in and start the container:

sed -i.bak 's/ gzip_level 9;//' default.conf && docker cp default.conf storefront:/etc/nginx/conf.d/default.conf && docker start storefront

How to prevent it

Validate the config before it ships, for example with nginx -t in CI or as a step before the copy. Keep the config in the repo so a bad change can be reverted in one step.

More incident guides