Docker regularly deletes the none image

When using docker, none image files will be generated, which is nothing occasionally, but for example, if you use an automated deployment tool , it will be different. There may be hundreds of none images in a day, which consumes resources very much, so it needs to be cleaned regularly

Delete the none mirror command

docker image prune -f

img.png img_1.png

Delete fragmented files in automated deployments

In automated deployment, Docker generates a lot of fragmented files. When using Jenkins to automate deployment projects, a lot of Images and created containers are generated. The above commands are not enough to delete, so the following commands must be used to delete

docker system prune -f

Note that this command will delete these containers and images, so it is best to choose carefully. Of course, it does not matter if all containers are automatically deployed.

after execution

In fact, clearing the cache files in this way is not the most complete way. The most complete way is to clear the idle Volumes (but I am afraid that the container will be automatically executed during the startup process and the data will be permanently lost. The gain outweighs the loss, so don’t add this)

docker system prune --volumes -f

Configure automation

Now that you know the command to delete the none mirror, it is simple, just configure the crontab

crontab -e

Add the following command at the end (indicating that it will be executed at 3:30 a.m. every day)

30 3 * * * docker system prune -f

Summarize

It seems that there is no automatic deletion function when using docker. I don’t know if there is a better way. This is relatively simple, so record it.

This article was originally created by " Cheng Ge Blog " and complies with the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: Docker regularly deletes the none image

Guess you like

Origin blog.csdn.net/Rakers1024/article/details/128105156