Docker container exits immediately (Exited (0) / Exited (1) right after start)
The container started and its main process finished at once, so the container stopped — Docker containers only live as long as PID 1.
Seen on:
Docker
Meaning
A container isn’t a VM: when CMD finishes, the container exits. Exited (0) means the command succeeded and ended (e.g. a script, or a service that daemonised into the background). Exited (1)/(2) means it crashed — the reason is in docker logs.
Common causes
- CMD runs a short task, not a long-running server
- Service starts in background/daemon mode (nginx without daemon off, service x start)
- App crashes on startup — missing env var, config or DB
- Running an OS image (ubuntu) with no command
⚡ Quick fix
- Read the output: docker logs <container>
- Run the server in the foreground (nginx -g 'daemon off;')
- For debugging keep it alive: docker run -it image sh
Detailed fix by platform
Docker
- bash
docker ps -a --format '{{.Names}}\t{{.Status}}' docker logs --tail 50 mycontainer
Dockerfile
CMD ["nginx", "-g", "daemon off;"]
How to diagnose
- Exit code — docker inspect -f '{{.State.ExitCode}}' c
- Logs — Last lines of docker logs
- Command — What does CMD/ENTRYPOINT run?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Docker
- daemon Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- COPY failed COPY failed: file not found in build context / "/app/x": not found
- compose validation docker compose: services.x Additional property y is not allowed / yaml: line N: mapping values are not allowed
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026