波神

导航

清理docker大日志文件

1、进入容器文件的存放目录 ,并查看某一个容器的文件大小

[root@auto ~]# 
[root@auto ~]# cd /var/lib/docker/containers
[root@auto containers]# du -sh *
32K    023e0d7025e56a77e562a306a7990808bea7ddc0f75d5d2e5bbfe69c05ad3f5c
32K    03ef1a60286ab4598aeb2dcff5fbbd373a021405eca307219ac502c9bd5fd96e
32K    1d906d1c611f8272e1a7ba59f0b997453a5168557ffb4075707e59498e63c25f
32K    346ba005ae6d973f0546c2866420ed08cf23f9412203275208ab21623155a453
576K    3bd43f437f2a7f142ae21046e02fb66a5daa3083da2d7833a82c509223a7b126
920K    6da5bf0c5edc3a051a722d133e58ca1c6dccc583df6d8c6f1f22c7abcb313b10
14M    80f5746d5a85a9256e9dd92cd7c7042561ec0f6f5efa8e219b25395a0fa00b5d
3.6M    9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16
94M    a70779e0f1a86a62f75f07bc4506a758d27b9af08a945344c1a6fd5ff1f77b05
624K    aa83cf4809489f02db75c7057caab74818b81275b8a0ed2c44f526bc067de228
28K    d27e04e08e946d3abcc85080944c8833315ca550b06a5031d3a552554332294e

 

2、进入某一个具体的容器比如:9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16

[root@auto containers]# cd 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16
[root@auto 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16]# du -sh *
3.6M    9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16-json.log
8.0K    config.v2.json
4.0K    hostconfig.json
4.0K    hostname
4.0K    hosts
4.0K    resolv.conf
0    shm
[root@auto 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16]# 

3、将日志文件清空

[root@auto 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16]# 
[root@auto 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16]# cat /dev/null>9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16-json.log
[root@auto 9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16]# du -sh *
0    9e20d3c20592021f5e16de7ee9314a20bc82ba6cea626765d04e94a28e03ba16-json.log
8.0K    config.v2.json
4.0K    hostconfig.json
4.0K    hostname
4.0K    hosts
4.0K    resolv.conf
0    shm

4、批量清理

#!/bin/bash

logfiles=$(find /var/lib/docker/containers/ -type f -name *-json.log)  
for logfile in $logfiles  
    do 
        cat /dev/null > $logfile  
    done 

 5、docker-comose里面控制日志文件

  mysql:
    image: mysql:latest
    container_name: mysql
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "5"

上面控制日志文件每个最大10M,最大5个文件

posted on 2018-11-21 17:40  波神  阅读(2087)  评论(0编辑  收藏  举报