Container exits immediately with code 0 right after `docker run -d`.
BeginnerTroubleshootingContainers that exit, crash or misbehave
Answer
Likely causes → The main process finished (a shell with no TTY, a script that ends, a daemon that forks into the background).
Diagnose →
docker ps -a
docker logs c
docker inspect -f '{{.Config.Cmd}} {{.Config.Entrypoint}}' c
Fix → Run the service in the foreground (nginx -g 'daemon off;'), or use -it for shells. A container lives as long as PID 1.
Prevent → Use images whose CMD is a foreground process.
More on Containers that exit, crash or misbehave
`Exited (137)` with no OOM flag.Intermediate`Exited (139)` segmentation fault.Advanced`Exited (126)` / `Exited (127)`.Beginner`exec /entrypoint.sh: exec format error`Intermediate`docker run` says `WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)` and the app is very slow.BeginnerApp crashes with `Error: listen EADDRINUSE: address already in use :::3000` inside the container.Beginner