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.
container exits immediatelycontainer stops right after startingExited (0) seconds ago 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
- docker-credential-desktop error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH
- pull access denied pull access denied for image, repository does not exist or may require 'docker login'
- lookup registry-1.docker.io: no such host dial tcp: lookup registry-1.docker.io: no such host / Temporary failure in name resolution during docker build
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026