📖 Scenario: You are managing a Docker environment on your computer. Over time, Docker containers and images use disk space. You want to check how much disk space Docker is using and clean up unused data to free space.
🎯 Goal: Learn how to check Docker disk usage and remove unused containers, images, and volumes safely.
📋 What You'll Learn
Use the docker system df command to check disk usage
Create a variable to hold the cleanup command
Use the cleanup command to remove unused Docker data
Display the disk usage before and after cleanup
💡 Why This Matters
🌍 Real World
Docker environments can fill up disk space quickly. Managing disk usage helps keep your system clean and fast.
💼 Career
DevOps engineers often need to monitor and clean Docker disk usage to maintain healthy CI/CD pipelines and production environments.
Progress0 / 4 steps
1
Check Docker disk usage
Run the command docker system df to see how much disk space Docker is using.
Docker
Hint
Type docker system df exactly to see disk usage summary.
2
Create cleanup command variable
Create a variable called cleanup_cmd and set it to the string docker system prune -f which will remove unused Docker data without asking for confirmation.
Docker
Hint
Assign the string 'docker system prune -f' to the variable cleanup_cmd.
3
Run the cleanup command
Use the variable cleanup_cmd to run the cleanup command and remove unused Docker data.
Docker
Hint
Use $cleanup_cmd to run the command stored in the variable.
4
Check disk usage after cleanup
Run docker system df again to see the disk usage after cleanup.
Docker
Hint
Run docker system df again to see updated disk usage.
Practice
(1/5)
1. What does the docker system df command show you?
easy
A. The disk space used by Docker images, containers, and volumes
B. The list of running Docker containers
C. The network settings of Docker containers
D. The logs of a specific Docker container
Solution
Step 1: Understand the purpose of docker system df and compare options
This command summarizes disk usage by Docker objects like images, containers, and volumes. Options B (docker ps), C (network settings), and D (logs) describe unrelated commands.
Final Answer:
The disk space used by Docker images, containers, and volumes -> Option A
Quick Check:
Disk usage summary = A [OK]
Hint: Remember 'df' means disk free or usage summary [OK]
Common Mistakes:
Confusing disk usage with container status
Thinking it shows logs or network info
Using it to list running containers
2. Which of the following commands correctly removes only all stopped containers to free disk space?
easy
A. docker container prune
B. docker image rm $(docker images -q)
C. docker system prune -a
D. docker container rm -f $(docker ps -a -q)
Solution
Step 1: Identify command to remove only stopped containers and check options
docker container prune safely removes all stopped containers only. A forcibly removes all containers (running and stopped). B removes images. C removes stopped containers plus unused images and networks (more than containers).
Final Answer:
docker container prune -> Option A
Quick Check:
Remove stopped containers = D [OK]
Hint: Use prune commands to safely clean stopped containers [OK]
Common Mistakes:
Using force remove on all containers including running ones
Confusing image removal with container removal
Using system prune when only containers should be removed
3. What will be the output of the command docker system df after running docker image prune -a?
medium
A. Error message about running containers
B. Disk usage report showing fewer images and freed space
C. List of all images including unused ones
D. No change in disk usage report
Solution
Step 1: Understand docker image prune -a effect on docker system df
This removes all unused images, freeing space, so the report shows fewer images and more free space. No error, no list, and usage changes.
Final Answer:
Disk usage report showing fewer images and freed space -> Option B
Quick Check:
Image prune frees space = B [OK]
Hint: Prune unused images to reduce disk usage [OK]
Common Mistakes:
Expecting an error when pruning images
Thinking prune lists images instead of removing
Assuming no change in disk usage after prune
4. You ran docker volume prune but still see high disk usage. What could be the reason?
medium
A. The prune command only cleans network settings
B. The prune command deleted running containers by mistake
C. Docker does not track volume disk usage
D. There are unused images and stopped containers still taking space
Solution
Step 1: Understand docker volume prune and reason for remaining usage
It removes unused volumes only. Unused images and stopped containers remain, causing high usage. No deletion of running containers or network cleaning.
Final Answer:
There are unused images and stopped containers still taking space -> Option D
Quick Check:
Volume prune only removes volumes = A [OK]
Hint: Prune volumes only frees volume space, check images and containers too [OK]
Common Mistakes:
Assuming volume prune deletes containers
Thinking prune affects network settings
Believing Docker ignores volume disk usage
5. You want to free maximum disk space but keep your running containers and their data intact. Which command should you use?
hard
A. docker container rm -f $(docker ps -q)
B. docker system prune --volumes
C. docker system prune -a --volumes
D. docker image rm $(docker images -q)
Solution
Step 1: Analyze options for maximum safe cleanup
docker system prune -a --volumes removes all stopped containers, all unused images (not just dangling), unused networks, and unused volumes--maximizing space--while keeping running containers and their data intact. C frees less (no -a). A removes running containers. D only images, unsafely and incompletely.
Final Answer:
docker system prune -a --volumes -> Option C
Quick Check:
Max prune safely, keep running containers = B [OK]
Hint: Use system prune with volumes to clean safely without stopping containers [OK]
Common Mistakes:
Using prune without -a flag, freeing less space
Force removing running containers causing downtime
Removing images only without cleaning volumes or containers
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.