Docker cleanup environment operation

Docker cleanup environment operation

Start cleaning carefully!

List unused volumes

docker volume ls -qf dangling=true

Clean up unused volumes

docker volume rm $(docker volume ls -qf dangling=true)

Clean up useless images

docker rmi $(docker images | grep '^<none>' | awk '{print $3}')

Continue cleaning

docker system prune

docker volume prune

The above are enough for use, don’t know other commands!

Additional knowledge: Docker article teaches you how to clean up Docker space to free up disk space

How to clean up the docker directory

The docker directory has filled up the system disk and is difficult to migrate. I want to ask if there is a quick solution. The answer is yes. The following are classic cases I have compiled, which are suitable for production and testing. Write a script to clean up the docker log as follows:

[root@www ~]# cat clean_docker_log_space.log 
#!/bin/bash
docker_log_files=$(find /var/lib/docker/containers/ -name '*-json.log')
docker_logs_size=$(find /var/lib/docker/containers/ -name '*-json.log' | xargs du -sc | tail -1 |awk '{print $1,"K"}')
free -h && sync && echo 1 > /proc/sys/vm/drop_caches #Release system cache echo -e "\033[32mThe docker log total size is $docker_logs_size\033[0m"
 
for log in $docker_log_files
  do
   echo "Now is cleaning docker log,docker core logs:$log"
    cat /dev/null > $log
    systemctl reload docker #Reload the docker service without affecting existing docker
  done 
 
free -h

The results are as follows:

[root@www ~]# ./clean_docker_log_space.log 
       total used free shared buff/cache available
Mem: 976M 598M 112M 6.8M 264M 157M
Swap: 511M 66M 445M
The docker log total size is 80 K
Now is cleaning docker log,docker core logs:/var/lib/docker/containers/7538f077348e3c9722fb90ed4b0a5c3d60d72112e989526767c63d55f5a76f3e/7538f077348e3c9722fb90ed4b0a5c3d60d72112e989526767c63d55f5a76f3e-json.log
Now is cleaning docker log,docker core logs:/var/lib/docker/containers/235d20190027e757a203f1b4d4093335fb92ba515f7a501448c36c1332c622a2/235d20190027e757a203f1b4d4093335fb92ba515f7a501448c36c1332c622a2-json.log
Now is cleaning docker log,docker core logs:/var/lib/docker/containers/685a7af447ce884de1e9bbeb5d4ca0ca99860096f71c33b4f9a4d15a427c5e00/685a7af447ce884de1e9bbeb5d4ca0ca99860096f71c33b4f9a4d15a427c5e00-json.log
       total used free shared buff/cache available
Mem: 976M 599M 176M 6.8M 200M 168M
Swap: 511M 66M 445M
 
[root@www ~]# find /var/lib/docker/containers/ -name '*-json.log' | xargs du -sc | tail -1 |awk '{print $1,"K"}'
0K

It is recommended to add the script to the Linux scheduled task and clean it up once a week. This can ensure that Docker does not generate additional log files.

The production environment is as follows

df -TH docker uses 93% of the system disk

Execute the script clean_docker_log_space.log. After executing the cleanup script, df -TH shows that docker uses 43% of the system disk.

Docker deployment suggestions

Finally, it is recommended that you deploy docker applications in the docker custom configuration directory

#First, mount the disk with the required capacity and select /data as the mount directory
[root@www ~]# mkdir -p /data
#Stop Docker
[root@www ~]# systemctl stop docker
 
#Move data to a new directory [root@www ~]# mv /var/lib/docker /data
#Modify configuration, add --graph /data
[root@www ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /data 
 
[root@www ~]# systemctl daemon-reload
[root@www ~]# systemctl start docker 
[root@www ~]# systemctl enable docker.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
 

The above Docker environment cleaning operation is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to Docker disk space cleaning
  • Common methods and problems of Docker cleaning
  • How to clean up the disk space occupied by Docker
  • How to regularly clean up docker private server images
  • 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

<<:  Solve the scroll-view line break problem of WeChat applet

>>:  SQL Optimization Tutorial: IN and RANGE Queries

Recommend

Summary of MySQL database and table sharding

During project development, our database data is ...

MySQL service and database management

Table of contents 1. Start and stop service instr...

Two ways to make IE6 display PNG-24 format images normally

Method 1: Please add the following code after <...

Eclipse configures Tomcat and Tomcat has invalid port solution

Table of contents 1. Eclipse configures Tomcat 2....

Detailed explanation of the usage and difference between nohup and & in Linux

Example: We use the Python code loop_hello.py as ...

Use a diagram to explain what Web2.0 is

Nowadays we often talk about Web2.0, so what is W...

Common repair methods for MySQL master-slave replication disconnection

Table of contents 01 Problem Description 02 Solut...

Detailed explanation of this pointing in JS arrow function

Arrow function is a new feature in ES6. It does n...

Vue+echarts realizes progress bar histogram

This article shares the specific code of vue+echa...

Implementation of adding remark information to mysql

Preface Some people have asked me some MySQL note...

A brief discussion on the corresponding versions of node node-sass sass-loader

Table of contents The node version does not corre...

Two ways to configure Vue global methods

Table of contents 1. Introduction 2. The first me...

Summary of some reasons why crontab scheduled tasks are not executed

Preface I recently encountered some problems at w...

mysql 8.0.19 winx64.zip installation tutorial

This article records the installation tutorial of...