php清理docker缓存,Docker空间使用分析与清理

  • Post author:
  • Post category:php


典型问题场景

用户发现Docker宿主机的磁盘空间使用率非常高。通过du逐层分析。

[root@SHDCTCAPPQA03 home]# du -h –max-depth=1|sort

5.8M ./user

86G .

86G ./iretailer

分析Docker空间分布

Docker 版本过低是没有 docker system 这个命令的

[root@SHDCTCAPPQA03 home]# docker system df

TYPE TOTAL ACTIVE SIZE RECLAIMABLE

Images 5 3 608.7MB 364MB (59%)

Containers 3 3 336.4MB 0B (0%)

Local Volumes 3 0 0B 0B

Build Cache 0B 0B

可以通过 docker system df -v 查看更详细的信息

[root@SHDCTCAPPQA03 home]# docker system df -v

Images space usage:

REPOSITORY TAG IMAGE ID CREATED ago SIZE SHARED SIZE UNIQUE SiZE CONTAINERS

javadr latest 521768d33a7f 4 months ago ago 161.9MB 107.8MB 54.1MB 1

mysql 5.5 87ce9047ca62 4 months ago ago 256.2MB 256.2MB 264B 1

hub.c.163.com/library/mysql 5.5 157f9c7bf6c6 14 months ago ago 256.2MB 256.2MB 0B 0

java 8-jre-alpine fdc893b19a14 16 months ago ago 107.8MB 107.8MB 0B 0

cloudwattfr/ntpserver latest 779ba01899da 2 years ago ago 190.6MB 0B 190.6MB 1

Containers space usage:

CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED ago STATUS NAMES

b431798d9a5d javadr:latest “java -jar app.jar” 0 336MB 3 months ago ago Up 4 weeks v01_iretailer

9b833c41381e mysql:5.5 “docker-entrypoint.s…” 0 53.8kB 3 months ago ago Up 7 weeks mysql_iretailer

1a69840b8ca6 cloudwattfr/ntpserver:latest “/usr/sbin/ntpd -n” 0 0B 3 months ago ago Up 7 weeks ntp-server

Local Volumes space usage:

VOLUME NAME LINKS SIZE

367830190cac5b8b3c6ffef9afe653fa674b326bc278bbd293823db06da3ed89 0 0B

4561f38abdf533fbb1e964fdf69d51cb7d847a497d5dd57abce23c2beab8a9fa 0 0B

9da07a60d5e0ff93196c4192c3344fb5947215e7e18a27b45538f111f80ed45c 0 0B

Build cache usage: 0B

空间清理

docker system prune 自动空间清理

[root@SHDCTCAPPQA03 home]# docker system prune –help

Usage: docker system prune [OPTIONS]

Remove unused data

Options:

-a, –all Remove all unused images not just dangling ones

–filter filter Provide filter values (e.g. ‘label==’)

-f, –force Do not prompt for confirmation

–volumes Prune volumes

手工清理

# 删除所有未被任何容器关联引用的卷:

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