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

Detailed explanation of how MySQL solves phantom reads

1. What is phantom reading? In a transaction, aft...

Implementation of deploying Apollo configuration center using docker in CentOS7

Apollo open source address: https://github.com/ct...

Detailed explanation of the use of CSS pointer-events attribute

In front-end development, we are in direct contac...

VMware15/16 Detailed steps to unlock VMware and install MacOS

VMware version: VMware-workstation-full-16 VMware...

Summary of 76 Experience Points of User Experience

Classification of website experience 1. Sensory e...

Analysis of examples of using anti-shake and throttling in Vue components

Be careful when listening for events that are tri...

The solution of html2canvas that pictures cannot be captured normally

question First, let me talk about the problem I e...

How to use shell scripts in node

background During development, we may need some s...

Two ways to remove the 30-second ad code from Youku video

I believe everyone has had this feeling: watching ...

JS Asynchronous Stack Tracing: Why await is better than Promise

Overview The fundamental difference between async...

How to configure MySQL8 in Nacos

1. Create the MySQL database nacos_config 2. Sele...

MySQL Billions of Data Import, Export and Migration Notes

I have been taking a lot of MySQL notes recently,...

Fabric.js implements DIY postcard function

This article shares the specific code of fabricjs...

How to create a Docker repository using Nexus

The warehouse created using the official Docker R...

6 solutions for network failure in Docker container

6 solutions for network failure in Docker contain...