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

ReactRouter implementation

ReactRouter implementation ReactRouter is the cor...

Solution to the problem of invalid width setting for label and span

By default, setting width for label and span is in...

Detailed explanation of using pt-heartbeat to monitor MySQL replication delay

pt-heartbeat When the database is replicated betw...

Remote development with VSCode and SSH

0. Why do we need remote development? When develo...

How to bind Docker container to external IP and port

Docker allows network services to be provided by ...

Use pictures to realize personalized underline of hyperlinks

Don't be surprised if you see some kind of und...

Detailed explanation of Vue3's responsive principle

Table of contents Review of Vue2 responsive princ...

Which loop is the fastest in JavaScript?

Knowing which for loop or iterator is right for o...

MySQL optimization tutorial: large paging query

Table of contents background LIMIT Optimization O...

Implementation steps for installing Redis container in Docker

Table of contents Install Redis on Docker 1. Find...

Mysql solution to improve the efficiency of copying large data tables

Preface This article mainly introduces the releva...

Javascript to achieve the effect of closing advertisements

Here is a case study on how to close ads using Ja...

Example of how to change the domestic source in Ubuntu 18.04

Ubuntu's own source is from China, so the dow...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...