Guide to Docker System Cleanup
The docker system prune -a
command is a powerful Docker command used to clean up your Docker environment by removing unused data 1. This command can help you free up significant disk space by deleting unused containers, networks, images, and optionally, volumes.
Basic Usage
docker system prune -a
This command will:
- Remove all stopped containers
- Remove all networks not used by at least one container
- Remove all dangling images (those not referenced by any container)
- Remove all build cache
Important Flags and Options
-a
or--all
: Removes all unused images, not just dangling ones.-f
or--force
: Bypass the confirmation prompt. Use with caution.--volumes
: Prune volumes in addition to the other items. This will remove all unused volumes.
Other Related Commands
-
docker system prune
: This is the base command without the-a
flag. It will only remove dangling images, stopped containers, unused networks, and build cache.docker system prune
-
docker image prune
: Remove unused or dangling images.docker image prune
-a
or--all
: Remove all unused images, not just dangling ones.-f
or--force
: Bypass the confirmation prompt.
-
docker container prune
: Remove all stopped containers.docker container prune
-f
or--force
: Bypass the confirmation prompt.
-
docker volume prune
: Remove all unused volumes.docker volume prune
-f
or--force
: Bypass the confirmation prompt.
-
docker network prune
: Remove all unused networks.docker network prune
-f
or--force
: Bypass the confirmation prompt.
Example
To remove all unused data, including volumes, without a confirmation prompt:
docker system prune -a --volumes -f
Caution
Using these commands, especially with the -a
and --volumes
flags, can delete important data if not used carefully. Always ensure that you understand what will be removed and that you have backups or necessary data saved elsewhere.
By understanding and utilizing the docker system prune -a
command and its related options, you can effectively manage and clean your Docker environment, ensuring it runs efficiently and without unnecessary clutter.