全局设置

通过对Docker服务配置文件修改,设置全局配置

vi /etc/docker/daemon.json

{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "1"
    }
}

systemctl daemon-reload
systemctl restart docker

人工清理已经存在的日志

查看所有容器的日志

1
2
3
4
5
6
7
8
9
#!/bin/sh 
echo "======== docker containers logs file size ========"  

logs=$(find /var/lib/docker/containers/ -name *-json.log)  

for log in $logs  
        do  
             ls -lh $log   
        done

cat方式可以清空当前日志,以后输出的日志会继续写入;

1
2
3
4
5
6
7
8
9
#!/bin/sh 
echo "======== start clean docker containers logs ========"  
logs=$(find /var/lib/docker/containers/ -name *-json.log)  
for log in $logs  
        do  
                echo "clean logs : $log"  
                cat /dev/null > $log  
        done  
echo "======== end clean docker containers logs ========"

[ 编辑 | 历史 ]
最近由“jilili”在“2021-03-05 00:52:47”修改