Docker容器技术干货docker

docker日志清理技巧

2019-05-26  本文已影响3人  ywandy

个人博客原文:
https://blog.ywandy.top/2019/05/25/docker%E6%97%A5%E5%BF%97%E6%B8%85%E7%90%86%E6%96%B9%E6%B3%95/

方法1: 使用脚本定期清理(手动删除docker 容器的log文件)

#!/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  
#!/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 ========"  

方法2: 通过设定docker容器的日志大小(达到容量会自动清理)

nginx: 
  image: nginx:1.12.1 
  restart: always 
  logging: 
    driver: “json-file” 
    options: 
      max-size: “5g”
# vim /etc/docker/daemon.json
{
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"}
}
上一篇下一篇

猜你喜欢

热点阅读