docker 日志清理

docker 日志定期清理

修改或新建daemon.json

vi /etc/docker/daemon.json

{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
	"log-driver":"json-file",
	"log-opts": {"max-size":"100m","max-file":"3"} 
}


max-file=3,意味着一个容器有三个日志,分别是id+.json、id+1.json、id+2.json,单个文件最大100m

下面两行是新添加的日志清理,有daemon.json就直接添加这两行,没有就新建一个daemon.json
"log-driver":"json-file",
"log-opts": {"max-size":"100m","max-file":"3"} 

重启生效

sudo systemctl daemon-reload
sudo systemctl restart docker
只针对于新创建的docker有效

查看docker占用的大小

#在overlay2目录下查找
root@ubuntu:/var/lib/docker/overlay2# du -sh *

6.7G    010b26b559edae49a782bbb2fefb660c4ccdc074ae440ee6103d2687a87a2248
32K     010b26b559edae49a782bbb2fefb660c4ccdc074ae440ee6103d2687a87a2248-init
180M    013629c31ee2993d6692706cd02baebe16be257f889ea9323a2fda93ab5ff680
40K     01534a0a2cacbcc988c9822fcb7ec8259d2b0c6178c0d6387e8cc261ed252bcd
1.2G    01c1feeb85c8ed8b3354fa7ecb76ea86aa26869f5d4e35d0373456df2d29aab1
636K    02ca8808ce1b9e32628f07bcca59e6312714db03ab86ad90c00b42dd78fd0f86
868K    064f975c418bbbbc92485febbcc0f556dd2bef097661342d3f2818bfcd763f4d
668M    067affc29ee4e6e9e7ef6dbf9d51e6091217d4f5dac43091ba2b8ca31e525ff0
32K     067affc29ee4e6e9e7ef6dbf9d51e6091217d4f5dac43091ba2b8ca31e525ff0-init
24K     0761de88ddf94c6a41f4c54779cb0d4eccbdb574661d37ae6b00f3534a09c02a
472K    08ed1fb66cecfafa95b1b985d414d82cf73b5af058104a5e2125781b99d7b27f
1004K   0b01cd317a6f7c4cf172381302056555a8c49fb7c8f72c65bb5371a265d52f80
32K     0b43127bb1085817e6f428c9dfbfd58f63913aea83ab10d4bac2a07333647ead


#再通过目录名查找容器名
 docker ps -qa | xargs docker inspect --format '{{.State.Pid}}, {{.Id}}, {{.Name}}, {{.GraphDriver.Data.WorkDir}}' | grep "46c628b1f6dc4436ba197aec0853db4c7e60a65fc075ceb275cc1bb99628c234"

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×