一:背景:服务器中磁盘空间打满,所有容器被终止
ncdu /后显示/var/lib/docker/containers/92084a2cba3625600c31daee8567cc83b828f53264351e550c61463f72cf0f45-json.log占用了11G空间
解决:cat /dev/null > /var/lib/docker/containers/92084a2cba3625600c31daee8567cc83b828f53264351e550c61463f72cf0f45-json.log
#不要使用rm -f删除,rm -f只会删除文件索引不会删除block,还要手动重启docker或者lsof|grep delete删除的进程在kill掉
优化:docker启动服务之前需要手动加上--log-driver json-file --log-opt max-size=10m
或者还可以配置/etc/docker/daemon.json
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "1"
}
}
systemctl daemon-reload && systemctl restart docker