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
docker logs --tail 5 storefrontThe 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.
cat default.confThe 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.
docker ps -aLists 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.
docker inspect -f '{{.State.Status}} exit={{.State.ExitCode}}' storefrontThe 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:4Root 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 storefrontHow 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
- Docker port mapping not working, empty reply
- Docker container cannot connect to the database host
- Docker volume permission denied
- Docker container exit code 137, killed for memory
- CrashLoopBackOff after a config change
- Service returns 503 while every pod is Running
- OOMKilled and exit code 137
- Pods fail to start after a Secret change
- Requests fail after adding a NetworkPolicy
- Healthy pods restarted by a liveness probe
- Slow service with low CPU and no restarts
- Rollout stuck on ImagePullBackOff
- Pods stuck Pending with insufficient CPU
- Linux disk full: no space left on device
- systemd service keeps restarting after a deploy
- Address already in use: find what holds a port on Linux
- Linux name or service not known after a config change
- Too many open files in a systemd service