Bird
Raised Fist0
Dockerdevops~10 mins

System prune for cleanup in Docker - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - System prune for cleanup
Start: Docker system prune command
↓
Check for unused containers
↓
Check for unused images
↓
Check for unused networks
↓
Check for unused build cache
↓
Remove all unused data
↓
Display freed space
↓
End
The system prune command checks for unused Docker data like containers, images, networks, and cache, then removes them to free space.
Execution Sample
Docker
docker system prune -f
This command removes all unused containers, images, networks, and build cache without asking for confirmation.
Process Table
StepActionEvaluationResult
1Run 'docker system prune -f'Identify unused containersList of stopped containers found
2Remove unused containersContainers removedSpace freed from containers
3Identify unused imagesDangling and unused images foundList of images to remove
4Remove unused imagesImages deletedSpace freed from images
5Identify unused networksNetworks not used by any container foundList of networks to remove
6Remove unused networksNetworks deletedSpace freed from networks
7Identify build cacheBuild cache foundCache to remove
8Remove build cacheCache deletedSpace freed from cache
9Display total space freedSummary shownUser sees total disk space reclaimed
10EndNo more unused dataCleanup complete
💡 All unused containers, images, networks, and build cache removed; system cleaned.
Status Tracker
Resource TypeStartAfter Prune
Containers (stopped)3 stopped containers0 stopped containers
Images (unused)5 dangling images0 dangling images
Networks (unused)2 unused networks0 unused networks
Build CacheSome cache dataNo cache data
Key Moments - 3 Insights
Why does the command remove stopped containers but not running ones?
The prune command only targets unused resources. Running containers are in use, so they are not removed. See execution_table rows 1 and 2 where only stopped containers are identified and removed.
What does the '-f' flag do in 'docker system prune -f'?
The '-f' flag forces the prune without asking for confirmation. This is why the command proceeds directly to removal steps in the execution_table without pause.
Does 'docker system prune' remove volumes?
By default, volumes are not removed. The command targets containers, images, networks, and build cache only. This is why volumes are not listed in the variable_tracker or execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step are unused images removed?
AStep 5
BStep 3
CStep 4
DStep 2
💡 Hint
Check the 'Action' column for image removal in the execution_table.
According to the variable tracker, how many stopped containers remain after prune?
A3
B0
C1
D5
💡 Hint
Look at the 'Containers (stopped)' row under 'After Prune' in variable_tracker.
If the '-f' flag is removed, what changes in the execution flow?
AThe command will ask for confirmation before removal
BIt will remove volumes as well
CIt will skip removing networks
DIt will remove running containers
💡 Hint
Recall the explanation about the '-f' flag in key_moments and how it affects confirmation.
Concept Snapshot
docker system prune -f
Removes all unused containers, images, networks, and build cache
Does not remove volumes by default
-f skips confirmation prompt
Frees disk space by cleaning unused Docker data
Full Transcript
The 'docker system prune -f' command cleans up unused Docker resources. It first finds stopped containers, unused images, networks, and build cache. Then it removes them all without asking for confirmation because of the '-f' flag. Running containers and volumes are not removed. After completion, it shows how much disk space was freed. This helps keep your Docker environment clean and saves storage space.

Practice

(1/5)
1. What does the Docker command docker system prune do?
easy
A. Stops all running containers immediately
B. Removes all unused containers, networks, images, and optionally volumes to free disk space
C. Updates Docker to the latest version
D. Creates a backup of all Docker images

Solution

  1. Step 1: Understand the purpose of system prune

    The docker system prune command is designed to clean up unused Docker data like stopped containers, unused networks, dangling images, and optionally volumes.
  2. Step 2: Identify what the command removes

    It removes unused resources to free disk space but does not stop running containers or update Docker.
  3. Final Answer:

    Removes all unused containers, networks, images, and optionally volumes to free disk space -> Option B
  4. Quick Check:

    System prune cleans unused Docker data = A [OK]
Hint: System prune cleans unused Docker data to free space [OK]
Common Mistakes:
  • Thinking it stops running containers
  • Confusing it with Docker update commands
  • Assuming it creates backups
2. Which of the following is the correct syntax to remove all unused images, containers, networks, and volumes with Docker system prune?
easy
A. docker system prune --all --volume
B. docker prune system -a --volumes
C. docker system prune -a --volumes
D. docker system prune -all -volumes

Solution

  1. Step 1: Recall correct Docker system prune syntax

    The correct command to remove all unused images, containers, networks, and volumes is docker system prune -a --volumes. The -a flag removes all unused images, and --volumes removes unused volumes.
  2. Step 2: Identify syntax errors in other options

    Options A, B, and D have incorrect command order or wrong flags like prune system or misspelled flags.
  3. Final Answer:

    docker system prune -a --volumes -> Option C
  4. Quick Check:

    Correct flags and order = C [OK]
Hint: Use '-a' and '--volumes' flags with 'docker system prune' [OK]
Common Mistakes:
  • Swapping 'system' and 'prune' keywords
  • Using incorrect flag names like '--volume'
  • Omitting the dash in flags
3. What will be the output after running docker system prune -a --volumes if you have 2 stopped containers, 3 unused images, 1 unused volume, and 1 unused network?
medium
A. No resources removed because containers are stopped
B. Removed 2 containers and 3 images only
C. Removed only unused volumes
D. Removed 2 containers, 3 images, 1 volume, and 1 network

Solution

  1. Step 1: Understand what the command removes

    The command docker system prune -a --volumes removes all unused containers (including stopped), all unused images, unused volumes, and unused networks.
  2. Step 2: Apply to given resources

    Given 2 stopped containers, 3 unused images, 1 unused volume, and 1 unused network, all will be removed by this command.
  3. Final Answer:

    Removed 2 containers, 3 images, 1 volume, and 1 network -> Option D
  4. Quick Check:

    All unused resources removed = A [OK]
Hint: System prune with '-a' and '--volumes' removes all unused resources [OK]
Common Mistakes:
  • Thinking stopped containers are not removed
  • Assuming volumes are not removed without extra flag
  • Confusing networks with containers
4. You ran docker system prune -a --volumes but received an error: unknown flag: --volumes. What is the likely cause?
medium
A. Docker version is outdated and does not support the --volumes flag
B. You need to run the command as root user
C. The flag should be --volume without 's'
D. You must stop all containers before pruning

Solution

  1. Step 1: Analyze the error message

    The error unknown flag: --volumes indicates Docker does not recognize the flag, likely due to an older Docker version.
  2. Step 2: Check other options

    Running as root is not required for this flag error. The correct flag is --volumes (with 's'), and stopping containers is not mandatory for the flag to work.
  3. Final Answer:

    Docker version is outdated and does not support the --volumes flag -> Option A
  4. Quick Check:

    Flag error means outdated Docker = D [OK]
Hint: Update Docker if flags are unrecognized [OK]
Common Mistakes:
  • Mistaking flag spelling as the cause
  • Assuming root user is required
  • Thinking containers must be stopped first
5. You want to free up disk space but keep volumes because they contain important data. Which command should you run?
hard
A. docker system prune
B. docker system prune -a --volumes
C. docker system prune --volumes
D. docker system prune -all -volumes

Solution

  1. Step 1: Understand volume preservation

    Volumes store important data and are not removed by default with docker system prune. The --volumes flag explicitly removes unused volumes.
  2. Step 2: Choose command that keeps volumes

    Running docker system prune without -a or --volumes removes stopped containers, unused networks, and dangling images but keeps volumes and unused images.
  3. Final Answer:

    docker system prune -> Option A
  4. Quick Check:

    Default prune keeps volumes = B [OK]
Hint: Avoid '--volumes' to keep volumes safe [OK]
Common Mistakes:
  • Using '-a' removes all unused images
  • Adding '--volumes' deletes volumes
  • Assuming default prune removes volumes
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