How to regularly clean up docker private server images

How to regularly clean up docker private server images

Using CI to build docker images for release has greatly improved everyone's version release efficiency, so the image repository has expanded rapidly. In order to relieve disk pressure, we need to set some cleanup strategies.

The cleanup strategies for different Docker images should be different. For example, the latest five versions of images are retained by default, all tool images are retained, and business images are retained for one month.

The simple way to keep 5 images is as follows:

Download https://github.com/mlabouardy/nexus-cli and use the cli to perform the removal.

download

wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/linux/nexus-cli
chmod +x nexus-cli

Configuration

./nexus-cli configure 

Finally, the .credentials file will be created in this directory

# Nexus Credentials
nexus_host = "http://nexus.demo.com"
nexus_username = "admin"
nexus_password = "adminpass"
nexus_repository = "your-docker-private-repo"

Note that the host and port of nexus filled in the host are not the port of the repo corresponding to docker.

nexus_repository is the repo corresponding to docker.

View Mirror

./nexus-cli image ls

Keep the last 5

./nexus-cli image delete -name mlabouardy/nginx -keep 5

Comprehensive script

clean.sh

image_file=image.txt
CLI_HOME=/data/nexus3
KEEP_VERSION_NUM=5

$CLI_HOME/nexus-cli image ls > $image_file
sed -i '$d' $image_file


cat $image_file | while read line
do
 echo "Clean up $line"
 $CLI_HOME/nexus-cli image delete -name $line -keep $KEEP_VERSION_NUM
done

Scheduled tasks

crontab -e

0 2 * * * sh /data/nexus3/clean.sh

Create a nexus task

think

As mentioned earlier, different retention strategies should be selected for different images. Of course you can't just keep 5. For example, a tool image may be developed very diligently, but the application may still be an old version. For business images, n releases were made in one day, and n images were added. How to maintain these versions?

A rough idea is to standardize the image name, such as adding prefixes such as tools-, biz-, etc.

Divided into different repos. For tools, use a separate repo, and for each business, use its own repo. Different retention policies are applied to different repos.

Summarize

The above is the method of regularly cleaning up docker private server images introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Solution to Docker disk space cleaning
  • Common methods and problems of Docker cleaning
  • Docker cleanup environment operation
  • How to clean up the disk space occupied by Docker
  • How to clean up junk files generated by Docker
  • How to quickly clean up docker resources
  • Docker cleanup command collection
  • How to Completely Clean Your Docker Data

<<:  MySQL 8.0.12 winx64 detailed installation tutorial

>>:  JavaScript method to detect the type of file

Recommend

Introduction to ufw firewall in Linux

Let's take a look at ufw (Uncomplicated Firew...

Example of using CSS to achieve semi-transparent background and opaque text

This article introduces an example of how to use ...

Share a Markdown editor based on Ace

I think editors are divided into two categories, ...

A brief introduction to MySQL dialect

Putting aside databases, what is dialect in life?...

Specific use of the wx.getUserProfile interface in the applet

Recently, WeChat Mini Program has proposed adjust...

Use of Linux sed command

1. Function Introduction sed (Stream EDitor) is a...

Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace rules in HTML In HTML, multiple spaces...

Using HTML+CSS to track mouse movement

As users become more privacy-conscious and take m...

Example code for implementing a text marquee with CSS3

Background Here's what happened, Luzhu accide...

Docker-compose steps to configure the spring environment

Recently, I need to package the project for membe...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

Two ways to implement HTML page click download file

1. Use the <a> tag to complete <a href=&...

Using react-beautiful-dnd to implement drag and drop between lists

Table of contents Why choose react-beautiful-dnd ...

How to delete a property of an object in JavaScript

1. delete delete is the only real way to remove a...