---
title: "Why does a Docker container exit immediately after running docker run -d ubuntu?"  
description: "Why does a Docker container exit immediately after running docker run -d ubuntu?"  
author: "Rana Sunny"  
published: 2026-09-30  
canonical: https://answers.mindstick.com/qa/117324/why-does-a-docker-container-exit-immediately-after-running-docker-run-d-ubuntu  
category: "Docker"  
tags: ["docker", "CLI", "DevOps", "troubleshooting", "Interview Questions"]  
reading_time: 1 minute  

---

# Why does a Docker container exit immediately after running docker run -d ubuntu?

I encountered a scenario during a hands-on technical assessment where I launched an Ubuntu container in detached mode using the following command:

```bash
# Launch an Ubuntu container in background mode
docker run -d --name test-container ubuntu

# List all containers to inspect status
docker ps -a
```

The output showed that the container was created, but immediately exited with code `0` instead of running continuously in the background. The interviewer asked me to explain the root cause of this behavior and demonstrate how to keep the container running.

I want to make sure I fully grasp the core concepts behind this question for future interviews. Specifically:

- How does Docker determine the lifecycle of a container based on its foreground Process ID 1 (PID 1)?
- Why does a default base image like `ubuntu` or `alpine` exit when no foreground command is specified?
- What are the standard techniques (e.g., passing interactive flags or overriding the default entrypoint/cmd) used to keep a utility container running during testing or debugging?


---

Original Source: https://answers.mindstick.com/qa/117324/why-does-a-docker-container-exit-immediately-after-running-docker-run-d-ubuntu

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
