/var/lib/docker/overlay2 占用很大,清理Docker占用的磁盘空间,迁移 /var/lib/docker 目录
一、du -hs /var/lib/docker/ 命令查看磁盘使用情况。
[root@*******0Z /]# du -hs /var/lib/docker/ 24G /var/lib/docker/二、docker system df命令,类似于Linux上的df命令,用于查看Docker的磁盘使用情况:
[root@****0Z /]# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 268 19 20.85GB 18.31GB (87%) Containers 20 20 18.97MB 0B (0%) Local Volumes 27 20 1.589GB 196.6kB (0%) Build Cache 0 0 0B 0B [root@****0Z /]#三、docker system prune命令可以用于清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)。
[root@iZ2vcihu837atk99kxj7j0Z /]# docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cache Are you sure you want to continue? [y/N] ydocker system prune -a命令清理得更加彻底,可以将没有容器使用Docker镜像都删掉。注意,这两个命令会把你暂时关闭的容器,以及暂时没有用到的Docker镜像都删掉了…所以使用之前一定要想清楚.。我没用过,因为会清理 没有开启的 Docker 镜像。
systemctl stop docker
mkdir -p /home/docker/lib
rsync -avz /var/lib/docker /home/docker/lib/
sudo mkdir -p /etc/systemd/system/docker.service.d/ sudo vi /etc/systemd/system/docker.service.d/devicemapper.conf
[Service] ExecStart= ExecStart=/usr/bin/dockerd --graph=/home/docker/lib/docker
systemctl daemon-reload systemctl restart docker systemctl enable docker
# docker info
... Docker Root Dir: /home/docker/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ ...
[root@***0Z /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE vmall/business-server 1.0.0.32 b5a05e9cfefa 2 hours ago 180MB vmall/business-server latest b5a05e9cfefa 2 hours ago 180MB vmall/goods-guarantee-server 1.0.0.32 9b3826ff6beb 2 hours ago 181MB vmall/goods-guarantee-server latest 9b3826ff6beb 2 hours ago 181MB vmall/goods-guarantee-server 1.0.0.31 291193969f2b 3 hours ago 181MB vmall/goods-guarantee-server 1.0.0.30 031501542d84 3 hours ago 181MB