Docker uses the Prune command to clean up the none image

Docker uses the Prune command to clean up the none image

The creation and confusion of none images

We occasionally see none images (virtual images), that's because

  1. During the image building process, many image builds were terminated due to script errors, resulting in many versions with the none tag.
  2. When manually building an image, no commit is made, leaving behind junk images
  3. These images take up a lot of 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 up None objects

Docker takes a conservative approach to cleaning up unused objects (often referred to as "garbage collection"), such as images, containers, volumes, and networks:
These objects are not normally deleted unless you explicitly ask Docker to do so. This may cause Docker to use additional disk space.
For each type of object, Docker provides a prune command.
Alternatively, you can use docker system prune to clean up multiple types of objects at once. This topic explains how to use these prune commands.

Trim Mirror

Clean up the none image (dangling image)
Command: docker image prune
By default, the docker image prune command only cleans up vanity images (images that are not tagged and 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 images that are not used by containers

Command: docker image prune -a

By default, you will be prompted to continue. To bypass the prompt, use the -f or --force flag.
You can use the --filter flag to limit which images are pruned using a filter expression. For example, to consider only images created 24 hours ago:

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

Pruning container

Stopping a container will not automatically delete the container unless the --rm flag is specified when starting the container. Use the docker ps -a command to view all containers on the Docker host, including stopped containers. You might be surprised at how many containers there are, especially in development environments. The writable layer of a stopped container still takes up disk space. To clean these up, use the docker container prune command:

$ 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 to continue. To bypass the prompt, use the -f or --force flag.

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

Trimming rolls

Volumes can be used by one or more containers and take up space on the Docker host. Volumes are never automatically deleted because doing so would 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 the network

Docker networks do not take up much disk space, but they do create iptables rules, bridge network devices, and routing table entries. To clean up these, you can use docker network prune to clean up networks that are not used by containers.

$ docker network prune

Trim Everything

The docker system prune command is a quick way to prune images, containers, and networks. In Docker 17.06.0 and earlier, pruning volumes is fine. In Docker 17.06.1 and later, you must explicitly specify the --volumes flag to the docker system prune command to prune 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 Docker 17.06.1 or higher, and you also want to prune volumes, 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

This is the end of this article about using the Prune command to clean up the none image in Docker. For more information about cleaning up the none image in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem that vim commands cannot be used in Docker containers
  • Docker compose configuration file writing and command usage examples
  • Basic introduction and use of Docker container image related commands
  • Use of docker system command set
  • Detailed explanation of docker basic commands and usage examples

<<:  Understanding MySQL index pushdown in five minutes

>>:  impress.js presentation layer framework (demonstration tool) - first experience

Recommend

MySQL chooses the appropriate data type for id

Table of contents Summary of Distributed ID Solut...

Detailed explanation of semiotics in Html/CSS

Based on theories such as Saussure's philosop...

Why should you be careful with Nginx's add_header directive?

Preface As we all know, the nginx configuration f...

Vue implements seamless scrolling of lists

This article example shares the specific code of ...

Summary of relevant knowledge points of ajax in jQuery

Preface Students who learn JavaScript know that A...

MySQL 8.0 DDL atomicity feature and implementation principle

1. Overview of DDL Atomicity Before 8.0, there wa...

Summary of MySQL time statistics methods

When doing database statistics, you often need to...

vitrualBox+ubuntu16.04 install python3.6 latest tutorial and detailed steps

Because I need to use Ubuntu+Python 3.6 version t...

How to find slow SQL statements in MySQL

How to find slow SQL statements in MySQL? This ma...

Introduction to the process of creating TCP connection in Linux system

Table of contents Steps to create TCP in Linux Se...

JS, CSS and HTML to implement the registration page

A registration page template implemented with HTM...

Tutorial on how to remotely connect to MySQL database under Linux system

Preface I recently encountered this requirement a...