How to periodically clean up images that are None through Jenkins

How to periodically clean up images that are None through Jenkins

Preface

In the process of continuous code delivery, when relying on Jenkins to produce Docker images, many intermediate images named None will be generated. These images are of little significance after the entire project production process is completed. They also take up space and need to be cleaned up regularly. Manual cleaning is really cumbersome, so there is regular cleaning.

Jenkins is a powerful application that allows for continuous integration and continuous delivery of projects, regardless of the platform used. It's a free source code that can handle any kind of build or continuous integration. Integration with Jenkins can be used for several testing and deployment techniques. Jenkins is a software that allows continuous integration.

Let’s take a look at the detailed introduction.

1. Manual cleaning

A relatively simple cleanup method is suitable for manually executing commands to clean up images when a single none image is generated. Execute the following command:

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

Since I don't have the mirror of none locally, I can only see the following effect when executing

2. Cleaning up after the project is completed

When building a CI-compliant project in Jenkins, cleanup after the production process is completed can be set in the build execution script, such as:

The script is:

echo ---------------Clear-Images...------------------
clearImagesList=$(docker images -f "dangling=true" -q)
if [ ! -n "$clearImagesList" ]; then
echo "no images need clean up."
else
docker rmi $(docker images -f "dangling=true" -q)
echo "clear success."
fi

When the project is built, execute this to clear the None image generated during its own construction process, so that it can clear its own intermediate products.

However, there is a serious problem. When two or more projects are being built at the same time, the cleanup script executed after the first build is completed will affect the project being built, and delete the none generated during the build process. However, the deletion fails and causes an error, causing the first project to fail to build. This method is not recommended for multiple projects. If there is only a single task running in Jenkins, there is no problem.

3. Scheduled task cleanup

I prefer this method. Create a new Jenkins scheduled task. For example, I set it to clean up the mirror of none at 12 o'clock in the evening. The steps are as follows:

1. Create a new project in Jenkins with any name, such as mine is ClearImage.

2. Build a trigger, select Poll SCM, and set the scheduled time. For example, I set it to clean up in the early morning, but you can also set other times. For specific setting rules, see the question mark on the right.

3. Execute the build script. The script content has been given before. Just save it.

Manually execute the immediate build to verify whether it is effective:

View the console output:

Output completed: Build worked.


Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to use Jenkins to configure Git+Maven automated build
  • Implementation of one-click deployment of Asp.net Core Jenkins Docker
  • How to build Jenkins+Maven+Git continuous integration environment on CentOS7
  • Jenkins installation and configuration notes
  • Detailed explanation of Docker+Jenkins+Gitlab+Django application deployment practice
  • Introduction to Jenkins and how to deploy Jenkins with Docker
  • Detailed explanation of how to use Log Parse in Jenkins
  • Docker container uses Jenkins to deploy web projects (summary)
  • Detailed explanation of how to automatically deploy springboot applications in Jenkins
  • Instructions for deploying projects to remote machines using the Publish Over SSH plugin in Jenkins

<<:  How to change the mysql password on the Xampp server (with pictures)

>>:  Implementing a simple carousel based on JavaScript

Recommend

Example of how to enable Brotli compression algorithm for Nginx

Brotli is a new data format that can provide a co...

React antd tabs switching causes repeated refresh of subcomponents

describe: When the Tabs component switches back a...

How to install and deploy MySQL 8.0 under CentOS8

MySQL 8 official version 8.0.11 has been released...

Solve the installation problem of mysql8.0.19 winx64 version

MySQL is an open source, small relational databas...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

Exploration and correction of the weird behavior of parseInt() in js

Background: I wonder if you have noticed that if ...

Pure CSS to achieve a single div regular polygon transformation

In the previous article, we introduced how to use...

CentOS 8 Installation Guide for Zabbix 4.4

Zabbix server environment platform ZABBIX version...

Vue implements a simple shopping cart example

This article example shares the specific code of ...

MySQL 8.0.13 installation and configuration graphic tutorial

Msyql database installation, for your reference, ...

Detailed explanation of JavaScript upload file limit parameter case

Project scenario: 1. Upload file restrictions Fun...

MySQL method steps to determine whether it is a subset

Table of contents 1. Problem 2. Solution Option 1...

How to install nginx under Linux

Nginx is developed in C language and is recommend...