【Docker】docker /var/lib/docker/aufs/mnt 目录满了,全是垃圾数据,咋搞?

时间:2023-11-24 11:31:20
#!/bin/bash

set +e

echo "START CLEAN PRO LOG..."
find /var/lib/docker/aufs/mnt -name '*.log' | xargs ./docker_echo_null.sh
find /var/lib/docker/aufs/mnt -name backups | xargs rm -rf
find /var/lib/docker/aufs/mnt -name glusterfs_client-3.5.-bin-ubuntu12..sh | xargs rm -rf
find /var/lib/docker/aufs/mnt -name nginx-1.6.-bin-ubuntu12..sh | xargs rm -rf
find /var/lib/docker/aufs/mnt -name uwsgi-2.0.-bin-ubuntu12..sh | xargs rm -rf

find /var/lib/docker/containers/ -type f -name '*-json.log' -exec tee {} \; </dev/null
find /var/lib/docker/aufs/mnt -name '*.log' -exec tee {} </dev/null \;
# echo '' | sudo tee $(docker inspect --format='{{.LogPath}}' <container_name_or_id>)
# find /var/lib/docker/aufs/mnt -name '*.log' -exec tee {} </dev/null \;
echo "CLEAN PRO LOG SUCCESS..." # RECOMMAND
# docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm # remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm # remove unused volumes:
apt-get install jq -y
find '/var/lib/docker/volumes/' -mindepth -maxdepth -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr

find . -type f -name gearwork.log -exec tee {} \; </dev/null

https://zhidao.baidu.com/question/501961425.html

find . -type f | xargs grep -l 'abc'
或find . -type f -exec grep -l 'abc' {} \;

find  /etc  -name “xxxx” -exec grep  'AAAA'  {}  \;  -print

命令:

#!/bin/bash

# 推荐方式
docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm
# remove exited containers: 
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)'
) | xargs -r rm -fr

【Docker】docker /var/lib/docker/aufs/mnt 目录满了,全是垃圾数据,咋搞?

参考资料:

https://lebkowski.name/docker-volumes/

https://gist.github.com/mlebkowski/471d2731176fb11e81aa#file-cleanup-docker-sh

http://blog.yohanliyanage.com/2015/05/docker-clean-up-after-yourself/