Back to troubleshooting
troubleshooting#docker#debugging

Docker: container exits immediately with no logs

A checklist for the classic 'my container starts and dies in a second' problem.

Jane Contributor August 2, 2026 2 views

Problem

You run `docker run my-image` and the container exits immediately. `docker ps` shows nothing; `docker ps -a` shows the container with `Exited (0)` or a non-zero code. There are no obvious logs.

Step-by-step Solution

  1. 1Run `docker logs <container-id>` (use `docker ps -a` to find the id). Even a crashed container keeps its stdout/stderr for a while.
  2. 2Add `-it` to run interactively: `docker run -it my-image` — sometimes the image's default CMD is a REPL that exits when stdin closes.
  3. 3Override the entrypoint and shell in: `docker run -it --entrypoint /bin/sh my-image` — you now have a shell inside the built image; run the intended command manually to see the real error.
  4. 4Check the `Dockerfile`'s `CMD` and `ENTRYPOINT` — a common mistake is `CMD python` with no script, which runs Python, gets no input, and exits.
  5. 5Confirm the app is a foreground process. Docker keeps a container alive **only as long as PID 1 is running**. Backgrounding your app with `&` or `nohup` makes the container exit immediately.
  6. 6For servers, ensure they bind to `0.0.0.0` — binding to `127.0.0.1` inside a container means nothing outside can reach it, but the container still runs. Not a crash, just unreachable.
  7. 7Add a `HEALTHCHECK` and monitor `docker inspect --format='{{json .State.Health}}' <id>` if the container starts but the app inside is unhappy.

See problem and detailed step-by-step above.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.