← Back to all fixes

Container exits immediately after start

The Issue

You run `docker run myapp` and the container stops immediately. `docker ps` is empty.

Root Cause

Docker containers only live as long as their PID 1 process. If your CMD finishes, exits, or crashes due to a missing env variable, the container dies with it.

How to Fix
  1. Check logs: `docker logs <container_id>`
  2. Run interactively to debug: `docker run -it myapp /bin/sh`
  3. Make sure CMD runs in the foreground. Wrong: `service nginx start` — Right: `nginx -g "daemon off;"`
  4. Check for missing required env variables that cause the app to crash on startup