Container states (created, running, paused, stopped)
📖 Scenario: You are learning how to manage Docker containers. Containers can be in different states like created, running, paused, or stopped. Understanding these states helps you control your applications better.
🎯 Goal: Build a simple Docker workflow to create a container, start it, pause it, and then stop it. You will check the container's state at each step.
📋 What You'll Learn
Use the docker command line tool
Create a container from the alpine image
Start, pause, and stop the container using Docker commands
Check the container state using docker ps -a
💡 Why This Matters
🌍 Real World
Managing container states is essential for running applications reliably in development and production environments.
💼 Career
DevOps engineers and system administrators use these commands daily to control application lifecycles and troubleshoot issues.
Progress0 / 4 steps
1
Create a Docker container
Use the command docker create --name mycontainer alpine sleep 3600 to create a container named mycontainer from the alpine image.
Docker
Hint
This command creates a container but does not start it. The container will be in the 'created' state.
2
Start the Docker container
Use the command docker start mycontainer to start the container named mycontainer.
Docker
Hint
Starting the container changes its state to 'running'.
3
Pause the Docker container
Use the command docker pause mycontainer to pause the running container named mycontainer.
Docker
Hint
Pausing a container freezes its processes but keeps it in memory.
4
Stop the Docker container and check its state
Use the command docker stop mycontainer to stop the container named mycontainer. Then use docker ps -a --filter name=mycontainer --format "{{.Names}} {{.Status}}" to display the container's name and current state.
Docker
Hint
Stopping the container ends its processes and changes its state to 'exited' or 'stopped'. The docker ps -a command shows all containers and their states.
Practice
(1/5)
1. Which Docker container state means the container is currently executing processes?
easy
A. stopped
B. created
C. paused
D. running
Solution
Step 1: Understand container states
The 'running' state means the container is actively executing its processes.
Step 2: Compare other states
'Created' means container is made but not started, 'paused' means temporarily halted, 'stopped' means container is not running.
Final Answer:
running -> Option D
Quick Check:
Active container = running [OK]
Hint: Running means container is actively working [OK]
Common Mistakes:
Confusing 'created' with 'running'
Thinking 'paused' means running
Mixing 'stopped' with 'running'
2. Which command shows all Docker containers including stopped ones?
easy
A. docker ps -a
B. docker pause
C. docker start
D. docker ps
Solution
Step 1: Recall docker ps usage
'docker ps' shows only running containers by default.
Step 2: Use option to show all containers
'docker ps -a' lists all containers, including stopped and paused ones.
Final Answer:
docker ps -a -> Option A
Quick Check:
Show all containers = docker ps -a [OK]
Hint: Add -a to see all containers, not just running [OK]
Common Mistakes:
Using 'docker ps' alone shows only running containers
Confusing 'docker start' with listing containers
Thinking 'docker pause' lists containers
3. What is the state of the container after running these commands?