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.
More on Live debugging tasks
A pod is in CrashLoopBackOff. You have 10 minutes. Walk through your commands.BeginnerThe pod shows `OOMKilled`. Diagnose and fix it.BeginnerA pod is stuck in `ImagePullBackOff`. Fix it.BeginnerA pod is `Pending` forever. What do you check?AdvancedThe Service returns "connection refused" but pods are Running. Debug it.Intermediate`docker build` fails with "COPY failed: file not found in build context". Fix it.Beginner