Docker uses the Prune command to clean up the none image

  • 2021-11-10 11:16:16
  • OfStack

Generation and confusion of directory none image How to Clean none Objects Trim mirror image
Clean up the image without container use
Trim container
Trimming roll
Pruning network
Trim 1 cut

The Generation and Confusion of none Mirror Image

We occasionally see none images (hanging images) because

Many mirror builds are terminated due to script errors during the mirror build process, resulting in many versions of none tags Spam image left behind when the image was built manually without submission These images occupy a large storage space and need to be deleted

As shown below


root@instance-o70no2nw:~# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              867c2dc0031b        12 hours ago        465MB
mytomcat            8.5.0               34c8c864d046        12 hours ago        465MB
ubuntu              16.04               a3551444fc85        2 days ago          119MB
mysql               8.0.16              d72169616e20        4 days ago          443MB
mysql               latest              d72169616e20        4 days ago          443MB
tomcat              latest              5a069ba3df4d        2 weeks ago         465MB

How to Clean none Objects

Docker takes a conservative approach to cleaning up unused objects (commonly referred to as "garbage collection"), such as mirrors, containers, volumes, and networks:
Unless Docker is explicitly asked to do so, these objects are usually not deleted. This may cause Docker to use extra disk space.
For each type of object, Docker provides one prune command.
In addition, you can use docker system prune1 to clean up multiple types of objects. This topic explains how to use these prune pruning commands

Trim mirror image

Clean none Image (Hanging Image)
Command: docker image prune
By default, the docker image prune command only cleans up nihilistic images (images that are not marked and are not referenced by any other images)


root@instance-o70no2nw:~# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

Clean up the image without container use

Command: docker image prune -a

By default, you will be prompted whether to continue. To bypass the hint, use the-f or--force flag.
You can use the--filter flag to use filter expressions to limit which images are trimmed. For example, consider only images created 24 hours ago:


$ docker image prune -a --filter "until=24h"

Trim container

The container is not automatically deleted after it is stopped, unless the rm flag is specified when the container is started. Use the docker ps-a command to view all containers on the Docker host, including stopped containers. You may be surprised that there are so many containers, especially in the development environment. The writable layer of the stopped container still takes up disk space. To clean this up, use the command docker container prune:


$ docker container prune

WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y

By default, you will be prompted whether to continue. To bypass the hint, use the-f or--force flag.

By default, all containers in the stopped state will be deleted. You can use the--filter flag to limit the scope. For example, the following command will only delete containers that were created 24 hours ago in a stopped state:

Trimming roll

Volumes can be used by one or more containers and occupy space on Docker hosts. Volumes will never be deleted automatically, because doing so will destroy data.


$ docker volume prune

WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y

Pruning network

Docker networks do not take up much disk space, but they create iptables rules, bridging network devices, and routing table entries. To clean up these things, you can use docker network prune to clean up the network that is not unused by the container.


$ docker network prune

Trim 1 cut

The docker system prune command is a shortcut to trim images, containers, and networks. In Docker 17.06.0 and earlier versions, it is good to trim volumes. In Docker 17.06.1 and later, you must explicitly specify the docker system prune command--the volumes flag will trim the volume.


$ docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

If you are using Docker 17.06.1 or later, and you also want to trim the volume, use the--volumes flag.


$ docker system prune --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

Related articles: