Bird
Raised Fist0
Dockerdevops~10 mins

Listing containers (docker ps, docker ps -a) - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Listing containers (docker ps, docker ps -a)
Start
↓
Run 'docker ps'
↓
Show running containers
↓
Run 'docker ps -a'
↓
Show all containers (running + stopped)
↓
End
The flow shows running 'docker ps' to list running containers, then 'docker ps -a' to list all containers including stopped ones.
Execution Sample
Docker
docker ps

docker ps -a
Lists running containers first, then lists all containers including stopped ones.
Process Table
StepCommandActionOutput ExampleNotes
1docker psList running containers onlyCONTAINER ID IMAGE STATUS NAMES abc123 nginx Up 2 hours webserverShows only containers currently running
2docker ps -aList all containers (running + stopped)CONTAINER ID IMAGE STATUS NAMES abc123 nginx Up 2 hours webserver def456 redis Exited (0) 3 hours redisdbShows all containers including stopped ones
💡 Commands complete after listing containers; no further action.
Status Tracker
VariableStartAfter 'docker ps'After 'docker ps -a'
Running Containers List[][{ID: 'abc123', Image: 'nginx', Status: 'Up 2 hours', Name: 'webserver'}][{ID: 'abc123', Image: 'nginx', Status: 'Up 2 hours', Name: 'webserver'}]
All Containers List[][][{ID: 'abc123', Image: 'nginx', Status: 'Up 2 hours', Name: 'webserver'}, {ID: 'def456', Image: 'redis', Status: 'Exited (0) 3 hours', Name: 'redisdb'}]
Key Moments - 2 Insights
Why does 'docker ps' show fewer containers than 'docker ps -a'?
'docker ps' shows only running containers (see execution_table step 1), while 'docker ps -a' shows all containers including stopped ones (step 2).
What does the 'Exited' status mean in 'docker ps -a' output?
'Exited' means the container has stopped running but still exists on the system, visible only with 'docker ps -a' (execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does 'docker ps' list at step 1?
AOnly running containers
BOnly stopped containers
CAll containers including stopped ones
DNo containers at all
💡 Hint
Check the 'Output Example' column in execution_table row for step 1.
At which step does the command show containers with status 'Exited'?
AStep 1
BBoth steps
CStep 2
DNeither step
💡 Hint
Look at the 'Output Example' column for 'Exited' status in execution_table.
If a container is stopped, which command will show it?
Adocker ps
Bdocker ps -a
Cdocker start
Ddocker run
💡 Hint
Refer to variable_tracker showing 'All Containers List' after 'docker ps -a'.
Concept Snapshot
docker ps: Lists only running containers.
docker ps -a: Lists all containers including stopped ones.
Use 'docker ps' to see active containers.
Use 'docker ps -a' to see full container history.
'Exited' status means container is stopped but exists.
These commands help manage container states quickly.
Full Transcript
This visual execution shows how 'docker ps' lists only running containers, while 'docker ps -a' lists all containers including stopped ones. Step 1 runs 'docker ps' and outputs running containers. Step 2 runs 'docker ps -a' and outputs all containers with their statuses. Variables track container lists after each command. Key moments clarify why outputs differ and what 'Exited' means. The quiz tests understanding of these differences and command outputs.

Practice

(1/5)
1. What does the command docker ps show by default?
easy
A. Only running containers
B. All containers, running and stopped
C. Only stopped containers
D. Docker images available locally

Solution

  1. Step 1: Understand the default behavior of docker ps

    The docker ps command lists containers that are currently running.
  2. Step 2: Compare with other options

    To see all containers, including stopped ones, you use docker ps -a. The command does not list images.
  3. Final Answer:

    Only running containers -> Option A
  4. Quick Check:

    docker ps = running containers [OK]
Hint: Remember: docker ps shows running containers only [OK]
Common Mistakes:
  • Thinking docker ps shows all containers
  • Confusing containers with images
  • Assuming stopped containers show without -a
2. Which of the following commands correctly lists all containers, including stopped ones?
easy
A. docker ps --stopped
B. docker ps
C. docker ps --running
D. docker ps -a

Solution

  1. Step 1: Identify the flag for listing all containers

    The -a flag with docker ps lists all containers, running or stopped.
  2. Step 2: Check other options

    docker ps alone shows only running containers. The options --running and --stopped are invalid flags.
  3. Final Answer:

    docker ps -a -> Option D
  4. Quick Check:

    docker ps -a = all containers [OK]
Hint: Use -a to list all containers, not just running [OK]
Common Mistakes:
  • Using docker ps without -a to see stopped containers
  • Trying invalid flags like --running
  • Confusing container listing with image listing
3. Given the following output from docker ps -a:

CONTAINER ID   IMAGE     STATUS              NAMES
abc123        nginx     Up 2 hours          webserver
def456        redis     Exited (0) 3 days ago cache
What will docker ps show?
medium
A. Both containers: webserver and cache
B. Only the cache container
C. Only the webserver container
D. No containers

Solution

  1. Step 1: Analyze the status of containers

    The container named webserver is "Up 2 hours" meaning it is running. The container named cache is "Exited", meaning it is stopped.
  2. Step 2: Understand docker ps output

    docker ps shows only running containers, so it will list only webserver.
  3. Final Answer:

    Only the webserver container -> Option C
  4. Quick Check:

    Running containers = webserver only [OK]
Hint: Check STATUS: 'Up' means running, 'Exited' means stopped [OK]
Common Mistakes:
  • Listing stopped containers with docker ps
  • Assuming all containers show without -a
  • Confusing container names with images
4. You run docker ps -a but get an error: unknown flag: --all. What is the likely cause?
medium
A. You typed --all instead of -a
B. Docker daemon is not running
C. You need to run the command as root
D. The container list is empty

Solution

  1. Step 1: Check the flag syntax

    The correct flag to list all containers is -a, not --all. The error shows the flag is unknown.
  2. Step 2: Rule out other causes

    If the daemon was not running, the error would be different. Running as root is not required for listing containers. An empty list does not cause a flag error.
  3. Final Answer:

    You typed --all instead of -a -> Option A
  4. Quick Check:

    Use -a flag, not --all [OK]
Hint: Use short flag -a, not --all [OK]
Common Mistakes:
  • Using invalid flag --all
  • Assuming root is needed for listing
  • Ignoring daemon status errors
5. You want to list all containers but only see their IDs and names, not other details. Which command achieves this?
hard
A. docker ps -a --short
B. docker ps -a --format "{{.ID}} {{.Names}}"
C. docker ps -a --quiet
D. docker ps --filter id --filter name

Solution

  1. Step 1: Understand formatting options

    The --format flag lets you customize output. Using {{.ID}} {{.Names}} shows only container IDs and names.
  2. Step 2: Evaluate other options

    --quiet shows only IDs, not names. --filter is for filtering, not formatting. --short is not a valid flag.
  3. Final Answer:

    docker ps -a --format "{{.ID}} {{.Names}}" -> Option B
  4. Quick Check:

    Use --format to customize output [OK]
Hint: Use --format to show only needed fields [OK]
Common Mistakes:
  • Using invalid flags like --short
  • Confusing --quiet with showing names
  • Trying to filter instead of format output
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard