Docker interview question · Most asked

How do you debug a container that exits immediately or behaves differently in production?

Summary

Check the exit code and logs (docker ps -a, docker logs <id>, docker inspect for state and OOMKilled), run it interactively with an overridden entrypoint (docker run -it --entrypoint sh image), and compare its environment, configuration, mounts, user and architecture with what you expect.

Longer Answer

Frequent causes: the main process runs in the background and the container exits (the main process must stay in the foreground); missing environment variables or config files; file permissions when running as non-root; wrong CPU architecture (exec format error when an arm64 image runs on amd64); and localhost assumptions. For running containers, docker exec -it <id> sh (or docker debug for images without a shell) lets you inspect from inside.

Key Points

  • Exit code, logs, inspect.
  • Override entrypoint to explore.
  • Foreground process; env; permissions; arch.
  • exec or docker debug into running containers.

More most-asked Docker questions

← All Docker questions