0%

/var/lib/docker/overlay2占用空间太大

执行df -h命令发现/var/lib/docker目录占用空间太大。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 898M 0 898M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 60M 851M 7% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 5.9G 12G 35% /
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 910M 4.0K 910M 1% /var/lib/kubelet/pods/0914bac1-2c2f-4294-a036-afe6fb5d2a16/volumes/kubernetes.io~secret/config
tmpfs 910M 4.0K 910M 1% /var/lib/kubelet/pods/7975066f-117d-4523-a55e-53262ed8f131/volumes/kubernetes.io~secret/config-volume
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/7454b8be-1bd2-4c17-9784-55bf49d0e6fd/volumes/kubernetes.io~secret/node-exporter-token-hwqlc
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/7975066f-117d-4523-a55e-53262ed8f131/volumes/kubernetes.io~secret/alertmanager-main-token-z4qrq
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/71e0ccae-267d-4025-b4ec-a5ccbd1f0adc/volumes/kubernetes.io~secret/kube-proxy-token-kq9lp
tmpfs 910M 4.0K 910M 1% /var/lib/kubelet/pods/e685593b-9684-48cc-a304-040b30707088/volumes/kubernetes.io~secret/config
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/53e83a95-4db5-48f7-b166-b37df18b38e0/volumes/kubernetes.io~secret/calico-node-token-f6g2m
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/0914bac1-2c2f-4294-a036-afe6fb5d2a16/volumes/kubernetes.io~secret/prometheus-k8s-token-sm6gd
tmpfs 910M 12K 910M 1% /var/lib/kubelet/pods/e685593b-9684-48cc-a304-040b30707088/volumes/kubernetes.io~secret/prometheus-k8s-token-sm6gd
overlay 17G 5.9G 12G 35% /var/lib/docker/overlay2/70944089660c7647c7a83e1dcef9d6297e3e440d4d2d4742f5d68448bde9ad95/merged
shm 64M 0 64M 0% /var/lib/docker/containers/e59d5037dc150cf7c2ed10ea94d8549c3b98e0b847980a1a306eda8dcaf7e6de/mounts/shm
overlay 17G 5.9G 12G 35% /var/lib/docker/overlay2/bbdeb82071f8c4cbb2d59e26721735d5f3fd82f8139c0a448133156a0f12631f/merged
overlay 17G 5.9G 12G 35% /var/lib/docker/overlay2/383c5b7d30028f38eca1e4f2b3ac6144d52b5b1e8f296f2314de9ca0fd867f7d/merged
shm 64M 0 64M 0% /var/lib/docker/containers/df1ee27e97c823d18fe76ca3a7195cd081e466527b3cf9169a9a9f816b4c3391/mounts/shm

执行docker ps -a发现大量已经停止或退出的容器,需要清理空间。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
64d81b1dc03026478f0114b657d4cd938967868967e5e5ee9b8ea3d72814a736
c5f180a1c5c2804d45d13d11f338d241e482ada9673bff0ba8cc18759ae4fcae
aa06316b5fd638c22fc41bd8f8ea4c511566c4c537c81bf5aad5f276ac6c2fae
ce5048ebf25bd48bbe1372aaf38c68078a05c06157ffcb4a8e646470f647acb0
0c4b37413e3483366fb640b94ad33596aef149a50bc610a2d720663159280871
7575ec0a092bc9d3dd1a54ac2e3b92ce0dd8f3f570565ecc918684b0c51087ea
1e335ee77f4167c19f6e54a1728d3d49775f651d871009752b1cfb7ec9fd7867
393bd6280ecf423804c27f264cfc95e72df7580dc6881bb1a249152b4554b10e
63ad5c44a30c80645e84b16cc8e1009e46235bd7001153f8d8d3c4887ed18786
ee8c92a30092e7c30338d2a6721d13f250c2a426947a29c2e2c30f9936c0e07a
cd49e432a75a5f9719e8436af70a40e9869e02db51c4f8c08f02ad26a6bdc3ba
35435e8cd10d2dd9b26993da909aba31f4d52df3475b30ba7536d473004c7e91
6028cf4eac7090a89c05edad7e45096130ee7e3336f28d2c0e2a890111d80043
6e1d20022ecdd871a684b016c89d4d1122c9c5a00de998f921e2eacbd54da482
6417077821f3fc76da1e436401b0ed58a842b8afec6134c3895d5f3c7ae8d069
b49f44b5a26aad43d9d7b0f1ff57b659d4aab90d13477063160862018d3ba6f3

Deleted Images:
untagged: nginx@sha256:b2d89d0a210398b4d1120b3e3a7672c16a4ba09c2c4a0395f18b9f7999b768f2
deleted: sha256:f7bb5701a33c0e572ed06ca554edca1bee96cbbc1f76f3b01c985de7e19d0657
deleted: sha256:8f1984cf0de0461043fcabd6b2a2040325ac001d9897a242e0d80486fe71575e
deleted: sha256:59d91a36ba4b720eadfbf346ddb825c2faa2d66cc7a915238eaf926c4b4b40ee
deleted: sha256:556c5fb0d91b726083a8ce42e2faaed99f11bc68d3f70e2c7bbce87e7e0b3e10
untagged: nginx@sha256:ee380d57f01eac528f59d031cbeff5eba98b077d25ebdc7d6aef6734f00a41b7
deleted: sha256:231d40e811cd970168fb0c4770f2161aa30b9ba6fe8e68527504df69643aa145
deleted: sha256:dc8adf8fa0fc82a56c32efac9d0da5f84153888317c88ab55123d9e71777bc62
deleted: sha256:77fcff986d3b13762e4777046b9210a109fda20cb261bd3bbe5d7161d4e73c8e

Total reclaimed space: 183.4MB

这样就删除了不用的容器和镜像了。