查看最新日志


docker logs --since 30s -f
#显示最新20行
docker logs --tail 20 -f
docker service logs goapi_recruit-schoolpi --tail 30 -f

清理命令一

sudo sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log'

清理脚本 docker-clean-logs.sh

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

运行方法


chmod +x ./docker-clean-logs.sh
docker stop xxxx
./docker-clean-logs.sh
docker start xxxx