Docker deletes useless images and other operations

Provide  prunecommands to remove unused images, containers, volumes, and networks.

Prune images

docker image pruneRemove images that have no tags and are not referenced by the container. Such images are called  dangling  images.

Example 1:docker image prune

Removed redis, no tags and no references

#docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
# docker images
REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
nginx                   latest    ae2feff98a0c   4 days ago     133MB
redis                   <none>    ef47f3b6dc11   8 days ago     104MB
centos                  latest    300e315adb2f   12 days ago    209MB
ubuntu                  latest    f643c72bc252   3 weeks ago    72.9MB
docs/docker.github.io   latest    32ed84d97e30   6 months ago   1GB
# docker image prune
# docker images
REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
nginx                   latest    ae2feff98a0c   4 days ago     133MB
centos                  latest    300e315adb2f   12 days ago    209MB
ubuntu                  latest    f643c72bc252   3 weeks ago    72.9MB
docs/docker.github.io   latest    32ed84d97e30   6 months ago   1GB

Example 2: Remove all images that are not used by the container -a

docker image prune -a
  •  

Skip the warning prompt: --forceor-f

docker image prune -f
  • 1

Example 3: Perform filter deletion:

Mirror created more than 24 hours

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

For the content of the filter, see the  docker image prune manual

Remove container s

When the container is stopped, it will not be deleted automatically unless it is specified in docker run  --rm. A stopped container writable layer will still take up disk space, so to clear it, use the  docker container prunecommand.

Other parameters are similar docker images prune

Remove volume

The volume will be used by one or more containers and occupy host space. The volume will not be automatically removed, because automatic removal will destroy the data.

docker volume prune
  •  

Other parameters are similar docker images prune

Remove network

Docker network does not take up disk space, but they create  iptablesrules, bridge network services, and route entries. Clear the network that is not used by the container, do so

docker network prune
  •  

Other parameters are similar docker images prune

Remove Everything

docker system prune The command is a shortcut to remove images, containers, and networks.

In Docker 17.06.0 and earlier, volumes can also be removed. In Docker 17.06.1 or later, you need to specify parameters --volumes.

Example (without removing 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
  •  

Example (with remove volume function): add--volumes

# 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
  •  

Other parameters are similar docker images prune

PS

If it helps you, please give me a thumbs-up and encourage you. Welcome to join the QQ technology exchange group of the top blog. Only technical exchanges in life and work, no substitute promotion, and no change. Let us move closer to poetry together.

  •  

Guess you like

Origin blog.csdn.net/qq_42533216/article/details/113518716