0
0
DockerComparisonBeginner · 4 min read

Docker prune vs system prune: Key Differences and Usage

The docker prune command removes unused Docker objects like containers, networks, or volumes selectively, while docker system prune cleans up all unused objects including images, containers, networks, and optionally volumes in one command. docker system prune is a broader cleanup tool compared to specific docker prune commands.
⚖️

Quick Comparison

This table summarizes the key differences between docker prune commands and docker system prune.

Featuredocker prune (e.g., container prune)docker system prune
ScopeCleans specific unused objects (containers, networks, volumes, or images)Cleans all unused objects at once (containers, networks, images, optionally volumes)
Command Variantsdocker container prune, docker network prune, docker volume prune, docker image pruneSingle command: docker system prune
Volume CleanupOnly with docker volume pruneOptional with --volumes flag
Confirmation PromptYes, asks before deletingYes, asks before deleting
Use CaseSelective cleanup of one resource typeBroad cleanup of all unused resources
Risk LevelLower risk, targets one resource typeHigher risk, can remove more data
⚖️

Key Differences

The docker prune commands are specific to resource types. For example, docker container prune removes only stopped containers, while docker network prune removes unused networks. This lets you clean up one type of resource without affecting others.

In contrast, docker system prune is an all-in-one cleanup command that removes all unused containers, networks, images, and optionally volumes with a single command. It is useful when you want to free up space quickly by removing all unused Docker objects.

Another difference is volume cleanup. Volumes are not removed by default in docker system prune unless you add the --volumes flag. With docker volume prune, only unused volumes are removed. Both commands ask for confirmation before deleting to prevent accidental data loss.

⚖️

Code Comparison

Here is how you remove all stopped containers using docker container prune:

bash
docker container prune
# You will be prompted to confirm deletion of all stopped containers.
Output
WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y Deleted Containers: container_id_1 container_id_2 Total reclaimed space: 500MB
↔️

docker system prune Equivalent

To remove all unused containers, networks, images, and optionally volumes, use docker system prune:

bash
docker system prune --volumes
# You will be prompted to confirm deletion of all unused objects including volumes.
Output
WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all build cache - all unused volumes Are you sure you want to continue? [y/N] y Deleted Containers: container_id_1 Deleted Networks: network_id_1 Deleted Images: image_id_1 Deleted Volumes: volume_id_1 Total reclaimed space: 2GB
🎯

When to Use Which

Choose docker prune commands when you want to clean up a specific type of Docker resource without affecting others. For example, use docker container prune to remove only stopped containers safely.

Choose docker system prune when you want a quick, broad cleanup of all unused Docker objects to free up space. Add the --volumes flag if you also want to remove unused volumes, but be cautious as this can delete important data.

Key Takeaways

docker prune commands clean specific unused Docker resources selectively.
docker system prune cleans all unused Docker objects in one go.
Use docker system prune --volumes to also remove unused volumes.
Both commands ask for confirmation before deleting to avoid accidental loss.
Choose selective prune for safety, system prune for broad cleanup.