doker 使用脚本清理容器日志

编辑sh脚本,

vim /var/lib/docker/containers/cleanLogs.sh

输入以下内容:

echo "======== docker containers logs file size ========"
logs=$(find ./ -name *-json.log)
for log in $logs
        do
             ls -lh $log
        done
 
echo "======== start clean docker containers logs ========"
logs=$(find ./ -name *-json.log)
for log in $logs
        do
                echo "clean logs : $log"
                cat /dev/null > $log
        done
echo "======== end clean docker containers logs ========"

保存之后修改文件权限

chmod 777 cleanLogs.sh

执行脚本

/. cleanLogs.sh

 

posted @ 2023-02-28 09:15  铁锅炖猫  阅读(60)  评论(0编辑  收藏  举报