概述
日常巡检过程中发现系统存储空间已满,根据du
命令发现/var/lib/docker/containers/
目录占用存储过多。
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 50G 50G 20K 100% /
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 16G 44M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda2 xfs 1014M 164M 851M 17% /boot
/dev/sda1 vfat 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home xfs 1.1T 42M 1.1T 1% /home
tmpfs tmpfs 3.1G 0 3.1G 0% /run/user/1001
tmpfs tmpfs 3.1G 40K 3.1G 1% /run/user/1000
overlay overlay 50G 50G 20K 100% /var/lib/docker/overlay2/06bd200667ecaf93f6ea4a46e4074bb8c02b81d565139c854acf58bb296674a9/merged
shm tmpfs 64M 0 64M 0% /var/lib/docker/containers/a3dfb66857aea43e4ad42b96a7753e8b243369fbd252a8f8b79463d989a91044/mounts/shm
处理办法
查看Log路径
[root@localhost ~]# docker inspect a3dfb66857ae|awk -F'"' '/LogPath/ {print $4}'
/var/lib/docker/containers/a3dfb66857aea43e4ad42b96a7753e8b243369fbd252a8f8b79463d989a91044/a3dfb66857aea43e4ad42b96a7753e8b243369fbd252a8f8b79463d989a91044-json.log
清理Log内容
[root@localhost ~]# truncate -s 0 `docker inspect a3dfb66857ae|awk -F'"' '/LogPath/ {print $4}'`
修改docker配置
编辑/etc/docker/daemon.json
文件新增或修改:
[root@localhost ~]# vim /etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
}
}
重启docker
单单重启docker服务目测无效,还需重新启动容器才有效。
[root@localhost ~]# systemctl restart docker