Exited (0) 🐳 Docker

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

  1. Read the output: docker logs <container>
  2. Run the server in the foreground (nginx -g 'daemon off;')
  3. For debugging keep it alive: docker run -it image sh

Detailed fix by platform

Docker

  1. bash
    docker ps -a --format '{{.Names}}\t{{.Status}}'
    docker logs --tail 50 mycontainer

Dockerfile

  1. CMD ["nginx", "-g", "daemon off;"]

How to diagnose

  1. Exit code — docker inspect -f '{{.State.ExitCode}}' c
  2. Logs — Last lines of docker logs
  3. 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:

🧠 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.