Managing Container States: A Beginner's Guide to Docker Lifecycle
Master container management by learning how to start, stop, and list containers. Get hands-on experience controlling the lifecycle of your Docker instances.

Previously in this course, we covered the basics of executing your first container in Running Hello World: Your First Docker Container Lifecycle. Now that you know how to launch a container, this lesson adds the ability to control its state—starting, stopping, and tracking containers as they move through their lifecycle.
The Container Lifecycle: Beyond the First Run
When you execute docker run, you are creating a new container instance from an image. However, a container isn't a "set it and forget it" process. In a real-world project, you will often need to pause, stop, or restart services as you develop your multi-service application. Understanding how to manage these states is the first step toward effective container management.
Conceptually, a container exists in one of three primary states:
- Running: The process is active and executing.
- Stopped: The process has exited, but the container file system and configuration persist on disk.
- Removed: The container is deleted entirely (we will cover this in a future lesson).
Practical Container Management Commands
To manage these states, we use the Docker CLI. Let’s look at the three most critical commands for daily operations.
1. Listing Active Containers
To see what is currently running on your host, use:
docker ps
This command provides a snapshot of your environment, showing the container ID, the image used, the status, and the ports mapped.
2. Stopping a Container
If you have a container running in the background (or even in the foreground), you can stop it gracefully. The Docker daemon sends a SIGTERM signal to the main process, allowing it to save state or close connections before shutting down.
docker stop <container_id>
3. Starting a Stopped Container
Once a container is stopped, it doesn't disappear; it simply enters an "Exited" state. To bring it back to life without creating a new instance, use:
docker start <container_id>
Worked Example: The Lifecycle Loop
Let's put this into practice. We will launch a lightweight web server container, observe it, stop it, and restart it.
-
Start a container in detached mode:
Bashdocker run -d --name my-web-server nginxThe
-dflag runs the container in the background. -
Verify it is active:
Bashdocker psYou should see
my-web-serverlisted in the output. -
Stop the container:
Bashdocker stop my-web-server -
Confirm it is gone from the active list:
Bashdocker psThe list will now be empty.
-
Restart the existing container:
Bashdocker start my-web-serverThe container resumes its previous state.
Hands-on Exercise
To advance our running project, follow these steps:
- Run a new container using the
alpineimage:docker run -d --name my-test-service alpine sleep 3600. - List the active container using
docker ps. - Stop the container.
- Verify the container has stopped by running
docker psagain. - Start it back up and verify its status.
Common Pitfalls
- Confusing
runwithstart: Many beginners try to usedocker runto restart a stopped container. Remember:runcreates a new instance. Usestartto resume an existing one. - Ignoring the Status: If you think a container is running but
docker psshows nothing, it likely exited due to an error. - Stopping too aggressively: If a container doesn't stop within 10 seconds of a
docker stopcommand, Docker will issue aSIGKILL(force kill). Always design your applications to handleSIGTERMsignals gracefully to avoid data corruption.
FAQ
Q: Does docker stop delete my data?
A: No. Data stored inside the container's writable layer remains intact until you explicitly remove the container.
Q: How do I see containers that aren't running?
A: docker ps only shows running containers. Use docker ps -a to list all containers, including those that have stopped.
Q: Why does my container exit immediately after starting? A: A container only stays "running" as long as its primary process (the entrypoint) is active. If the process finishes, the container stops.
Recap
Container management is about controlling the lifecycle of your instances. By mastering docker ps to view status, and docker start/docker stop to transition between states, you keep your environment organized and efficient. These commands are the foundation of managing the multi-service application we are building throughout this course.
Up next: We will dive deeper into container visibility by learning how to use docker ps -a to inspect stopped containers and view logs to debug why a container might have failed.
Work with me

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.
