Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to automatically clear the none image of Docker

Shulou Source: shulou.com Published: 2022-05-31 20:22:58 09月18日 Update

This article mainly explains "how to automatically remove the none image of Docker". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to automatically remove the none image of Docker".

In docker build or pull, a mirror is often generated, which is called dangling in Docker, and is characterized by the fact that label is none.

A large number of none images will burst the disk, resulting in disk full, unable to create files.

1. The docker image labeled as

The following is a set of none images:

[root@ccg] # docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

Centos6.5 v2 434c6fa14315 9 seconds ago 254.8 MB

819f53017d76 56 minutes ago 254.8 MB

II. Clean-up methods

How do I clear the mirror?

1. Use docker image prune

two。 Use docker rmi

Let's start with the first one:

To delete a mirror using docker prune, we just need to execute:

Docker image prune-f

The second way:

Docker rmi-f `docker images | grep''| awk'{print $3}'`

In addition, we often need to clean up the abnormal exit containers in the system.

Docker rm `docker ps-a | grep Exited | awk'{print $1}'`

III. Configuration automation

Automatic deletion of configuration, configure crontab on the corresponding machine

1. Crontab-e

two。 Add the following directive (remove the image of the none tag and the exception exit container before the wee hours of the morning, respectively)

59 23 * docker rmi-f `docker images | grep''| awk'{print $3}'`

59 23 * docker rm `docker ps-a | grep Exited | awk'{print $1}'

Thank you for your reading, the above is the content of "how to automatically remove the none image of Docker". After the study of this article, I believe you have a deeper understanding of how to automatically remove the none image of Docker, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Mirroring learning configuration content containers that is ways times tags automation just regular meetings ideas situations instructions files articles more machines features Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Shulou Information Redmi Apple