A Docker container exits immediately after `docker run -d`. Find out why.

BeginnerHands-onLive debugging tasks
Answer
docker ps -a --filter name=api               # STATUS: Exited (1) 3 seconds ago
docker logs api
docker inspect api --format '{{.State.ExitCode}} {{.State.Error}} {{.Config.Cmd}} {{.Config.Entrypoint}}'
docker run --rm -it --entrypoint sh myapp:1.0    # get a shell in the same image and run the command by hand

Key trick → A container lives only as long as its main process. -d with a command that finishes (or a service that daemonises itself, like nginx without daemon off;) exits at once. Overriding --entrypoint lets you look inside.

All Real-World Interview questions Roadmap: Interview readiness

More on Live debugging tasks