Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Troubleshooting Cleaning Up Unused Resources docker system prune docker image prune docker container prune docker volume prune docker network prune
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-troubleshooting-cleaning-up-unused-resources-docker-system-prune-docker-image-prune-docker-container-prune-docker-volume-prune-docker-network-prune

Docker Docker Troubleshooting Cleaning Up Unused Resources docker system prune docker image prune docker container prune docker volume prune docker network prune

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

Cleaning up unused Docker resources frees up disk space and improves system performance. docker system prune.

2. Step-by-Step

  1. Check for unused resources: docker system df
  2. ⚠️ Decide to prune all unused resources: docker system prune -a
  3. Confirm the deletion: docker system prune -a --volumes
  4. Check for unused images: docker images -a
  5. ⚠️ Decide to prune all unused images: docker image prune -a
  6. Confirm the deletion: docker image prune -a --force
  7. Check for unused containers: docker ps -a
  8. ⚠️ Decide to prune all stopped containers: docker container prune
  9. Check for unused volumes: docker volume ls
  10. ⚠️ Decide to prune all unused volumes: docker volume prune
  11. Check for unused networks: docker network ls
  12. ⚠️ Decide to prune all unused networks: docker network prune

3. Real Commands with Examples


Example 1: Prune Unused Images

Purpose: Remove unused Docker images.
Command: docker image prune -a Flags: -a removes all unused images, --force forces the deletion.

Example 2: Prune Unused Containers

Purpose: Remove stopped Docker containers.
Command: docker container prune Flags: None, but be cautious as this deletes all stopped containers.

Example 3: Prune Unused Volumes

Purpose: Remove unused Docker volumes.
Command: docker volume prune Flags: None, but be cautious as this deletes all unused volumes.

4. Common Errors


Error 1: "Error response from daemon: You cannot remove a volume that is in use"

Error message or symptom: Unable to prune a volume.
Why it happens: The volume is still in use by a container.
One-line fix: docker container stop <container_name> && docker volume prune

Error 2: "Error response from daemon: You cannot remove a network that is in use"

Error message or symptom: Unable to prune a network.
Why it happens: The network is still in use by a container.
One-line fix: docker network disconnect <network_name> <container_name> && docker network prune

Error 3: "Error response from daemon: You cannot remove an image that is being used by a container"

Error message or symptom: Unable to prune an image.
Why it happens: The image is still in use by a container.
One-line fix: docker container stop <container_name> && docker image prune -a

5. Quick Checks


Scenario 1: Check for unused images

Situation: You want to free up disk space.
Command to run: docker images -a Correct response: A list of unused images with their IDs and sizes.

Scenario 2: Check for unused containers

Situation: You want to remove stopped containers.
Command to run: docker ps -a Correct response: A list of stopped containers with their IDs and names.

Scenario 3: Check for unused volumes

Situation: You want to remove unused volumes.
Command to run: docker volume ls Correct response: A list of unused volumes with their names and sizes.

6. Last-Minute Reference

-a flag: removes all unused resources.
--volumes flag: includes volumes in the prune operation.
--force flag: forces the deletion of resources.
docker system df: displays disk usage statistics.
docker system prune -a: removes all unused resources.
docker image prune -a: removes all unused images.
docker container prune: removes all stopped containers.
docker volume prune: removes all unused volumes.
docker network prune: removes all unused networks.
• ⚠️ Be cautious when using docker system prune -a, docker image prune -a, docker container prune, and docker volume prune as they delete resources permanently.




ADVERTISEMENT