beginnerImages, Layers, Caching & Container Lifecycle

If a container's main process forks a background daemon and then the main process exits, does the container keep running?

No. Docker tracks the lifecycle of PID 1 specifically. The moment PID 1 exits — regardless of any child or background processes it spawned — the container is considered Exited, and any remaining processes in that container's namespace are killed.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Image keeps growing across rebuilds despite removing files← Back to all Docker questions