687
清理docker运行占用的磁盘空间
乐果 发表于 2023 年 03 月 08 日 标签:Docker
docker
运行时会产生日志,时间久了占用宿主机磁盘空间非常大,可以通过设置日志文件大小限制,也可以定期清除文件。
下面,清理 docker
运行占用的磁盘空间为例。
df 查看磁盘使用情况
df -h
Filesystem Size Used Avail Use% Mounted on
udev 924M 0 924M 0% /dev
tmpfs 188M 856K 188M 1% /run
/dev/vda1 40G 36G 1.7G 96% /
tmpfs 940M 0 940M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
overlay 40G 36G 1.7G 96% /var/lib/docker/overlay2/4d0744e41be2f1576b3c2a67d74af621738d37c85e305d75e0bf6fe2d2c3777f/merged
tmpfs 50M 0 50M 0% /usr/local/aegis/cgroup
overlay 40G 36G 1.7G 96% /var/lib/docker/overlay2/4a4a729a84a73b77b9a82daf2f2405412bb8e0a48ab41feda7ceca4438d375aa/merged
overlay 40G 36G 1.7G 96% /var/lib/docker/overlay2/6d4dd9f4a32de946509ed6d885d97660919dd60fff115ecbb322e9351f40cd36/merged
overlay 40G 36G 1.7G 96% /var/lib/docker/overlay2/4fb297559aa05464b68454b4bec76f57e7b61e30a4bfad4178a4a9c052650ade/merged
tmpfs 188M 0 188M 0% /run/user/0
查看docker容器占用情况
docker system df -v
Images space usage:
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
hub.wesais.cn/edge/caddy 2.5.1-alidns 3a0b492cc55f 8 months ago 82.64MB 44.37MB 38.27MB 1
caddy 2.5.1-builder-alpine c80070b3eb60 9 months ago 344.3MB 0B 344.3MB 0
snowdreamtech/frps latest 979d136fb73a 9 months ago 19.61MB 5.575MB 14.03MB 1
portainer/portainer-ce latest 7b6e59279c38 10 months ago 274.9MB 0B 274.9MB 1
caddy 2.5.1 e63f36e9049f 10 months ago 44.37MB 44.37MB 0B 0
ffdfgdfg/nps latest 52ebfd4ed926 23 months ago 15.14MB 0B 15.14MB 1
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
7322359af98a snowdreamtech/frps:latest "/bin/sh -c '/usr/bi…" 0 135B 8 months ago Up 8 months frps
3bd5cf44f1e1 hub.wesais.cn/edge/caddy:2.5.1-alidns "caddy run --config …" 2 271B 8 months ago Up 8 months proxy-caddy-1
6cfb0bb63cfd ffdfgdfg/nps "/nps" 0 0B 9 months ago Up 46 hours nps
248dc2c11fda portainer/portainer-ce "/portainer" 1 0B 9 months ago Up 8 months portainer-ce
Local Volumes space usage:
VOLUME NAME LINKS SIZE
proxy_caddy_proxy_data 1 6.58kB
portainer_data 1 114.1kB
proxy_caddy_proxy_config 1 880B
Build cache usage: 0B
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
清除没有使用过的镜像
docker system prune
进入docker目录,查看容器目录大小
cd /var/lib/docker/overlay2/
du -h --max-depth=1
在docker目录下查找容器运行的日志文件
find /var/lib/docker/containers/ -name *-json.log |xargs du -sh
60K /var/lib/docker/containers/248dc2c11fda372bbbe6003a9b0792777b1552a0170888f252f7ccfabbddd615/248dc2c11fda372bbbe6003a9b0792777b1552a0170888f252f7ccfabbddd615-json.log
32G /var/lib/docker/containers/6cfb0bb63cfd6cc0d89e4118a503ff892a0b6420f01613591803cdeb6bc40655/6cfb0bb63cfd6cc0d89e4118a503ff892a0b6420f01613591803cdeb6bc40655-json.log
8.7M /var/lib/docker/containers/7322359af98a17402d3464de1c963275200775192d6c8cae2756431f6f12b3ce/7322359af98a17402d3464de1c963275200775192d6c8cae2756431f6f12b3ce-json.log
328K /var/lib/docker/containers/3bd5cf44f1e143b54aee2402a97274b59b666d22619c42e083ccf287d08b8826/3bd5cf44f1e143b54aee2402a97274b59b666d22619c42e083ccf287d08b8826-json.log
找到日志文件后,将它清空
cat /dev/null > /var/lib/docker/containers/6cfb0bb63cfd6cc0d89e4118a503ff892a0b6420f01613591803cdeb6bc40655/6cfb0bb63cfd6cc0d89e4118a503ff892a0b6420f01613591803cdeb6bc40655-json.log
乐果 发表于 2023 年 03 月 08 日 标签:Docker