Docker disk clean up garbage

1, the overall analysis

For Docker, the existence of the mirror, the container storage volume and network objects. Therefore, it will be the production of these objects corresponding to these objects take up disk space. When these objects are not being used, in order not to take up additional disk space, you need to clean up these objects, that is garbage. After docker version 1.13, it provides a prune command of various objects, but also provides clean all types of objects docker system prune command. But in versions prior to 1.13 docker, we need to provide other means garbage.

2, garbage clean-up

Garbage clean-up version after 2.1 docker v1.13

2.1.1 container

When the container is stopped, the system does not know to delete this container, set up -rm field unless you run this container. Container after stopping still occupy disk storage space, these containers can be deleted after being stopped by the docker container prune.

$ docker container prune

WARNING! This will remove all stopped containers.

Are you sure you want to continue? [y/N] y

When this command is executed, the default will be prompted whether to continue. If you execute the command is set -f or -force field, it will directly delete all stopped container. By default, this command removes all the containers have been stopped when performed either by setting -filter field to filter container to be deleted. For example, the following command to delete stop just over 24 hours in the container.

$ docker container prune --filter "until=24h"

2.1.2 Mirror

You can clear all images no longer used by executing docker images prune command, by default, this command is only cleared as dangling the mirror. Dangling state is unsubstituted tagging mirror and the mirror is not referenced in any container.

$ docker image prune

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

If you want to remove all unused mirror is achieved by setting -a field:

$ docker image prune -a

WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y

When this command is executed, the default will be prompted whether to continue. If you execute the command is set -f or -force field, it will directly delete operation. -Filter field by setting, to filter the image to be deleted. For example, the following command to delete stop just over 24 hours to create a mirror image.

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

2.1.3 storage volume

Storage volume or a plurality of containers may be used, it will occupy disk space. To maintain data storage volume will never automatically deleted.

$ 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

When this command is executed, the default will be prompted whether to continue. If you execute the command is set -f or -force field, it will directly delete operation. By default, this command will delete all of the implementation of unused storage volume, you can also set -filter field to filter storage volumes to be deleted. For example, the following command to delete only keep the value of the storage volume label.

$ docker volume prune --filter "label!=keep"

2.1.4 Network

docker network and does not take up disk space, but will create iptables rules, equipment and bridge network routing tables. Therefore, it is no longer how to use these resources, should be cleaned.

$ docker network prune

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

When this command is executed, the default will be prompted whether to continue. If you execute the command is set -f or -force field, it will directly delete operation. By default, this command will remove all unused network execution, you can also set -filter field to filter the network to be removed. For example, the following command is only more than 24 hours to be used for the network.

$ docker network prune --filter "until=24h"

2.1.5 Remove all objects

To quickly remove all objects not used by the docker system prune command, including a mirror, a container, and the network storage volumes. Before docker 17.06.0, storage volume will also be cleared. After docker 17.06.1, by setting the -volumes field, it will simultaneously clean up storage volumes.

$ 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 later versions 17.06.1 docker, you need to add -volumes field after the command to clean up the contents of a storage volume.

$ 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

Prior to 2.2 docker v1.13 version of rubbish

2.2.1 container

When the container is stopped, the system does not know to delete this container, set up -rm field unless you run this container. Container after stopping still occupy disk storage space, these containers can be deleted after being stopped by docker rm. The following command can clear all stopped container.

$ docker rm $(docker ps -a -q)

2.2.2 Mirror

Clear all the images no longer used by the command execution docker rmi, generally only cleared state dangling mirror. Dangling state is unsubstituted tagging mirror and the mirror is not referenced in any container.

$ docker rmi $(docker images -q -f "dangling=true")

2.2.3 storage volume

Storage volume or a plurality of containers may be used, it will occupy disk space. In order to maintain data storage volume will never automatically deleted.

$ docker volume rm $(docker volume ls -q -f dangling=true)

Guess you like

Origin www.cnblogs.com/sea520/p/11374345.html