A few days ago, we found that the hard disk of a certain server gave an alarm , Clean up right away . use df Command to view hard disk , Insufficient hard disk space found 60%, Hard disk inode It was used 82%, There are a lot of small files that take up hard disk space .

then , The discovery is due to the docker container , A lot of cache and other junk files are generated . Found a lot of documents , After testing , Just finished cleaning up . Here is docker Summary of cleaning up garbage documents .

( It can be used by personal test . because docker Container's service is in use , Other risky commands were not used , The following commands are relatively safe and reliable , Enough to clear the space )

One , Hard disk occupancy view
【1】 Hard disk space view
df -TH

【2】inode see
df -i

【3】Docker Occupied disk space view
docker system df

docker system Is a command for managing disk space ,docker system df, be similar to df command , Specifically for viewing docker Disk usage for .

Two ,docker clear
Before using the command, confirm whether it can be deleted

【1】 Delete all containers that have been stopped

be careful : You should first confirm whether there are any containers that can not be deleted , You can also delete and use the image to start another container .
docker rm $(docker ps -a|grep Exited |awk '{print $1}') docker rm $(docker ps -
qf status=exited)
【2】 Delete all unlabeled images
docker rmi $(docker images -q -f dangling=true)
【3】 Delete all useless volume
docker volume rm $(docker volume ls -qf dangling=true)
【4】 Clean up the disk , Delete closed containers , Useless data volumes and networks
parameter : -a : When clearing all mirrors without container references , use docker system prune -a ( Use with caution ) -f or --force : Forced purge ,
There will be no prompt , use docker system prune -f( Use with caution ) --filter : Used to limit the range of mirrors to be retained , for example : Only clear over creation time over 24
Mirror image of hours (docker image prune-a --filter "until=24h") docker system prune

Three ,docker extend
【1】 Stop all running containers
docker stop $(docker ps -q)
【2】 Stop all containers
docker stop $(docker ps -a -q)
【3】 Delete all containers

This command removes all stopped containers , Cannot delete a running container
docker rm $(docker ps -aq)
【4】 Delete all mirrors
docker rmi $(docker images -q)

©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?