Thứ Ba, 8 tháng 10, 2019

Script Flush log của Docker nhanh

#!/bin/bash -e

if [[ -z $1 ]]; then
    echo "No container specified"
    exit 1
fi

if [[ "$(docker ps -aq -f name=^/${1}$ 2> /dev/null)" == "" ]]; then
    echo "Container \"$1\" does not exist, exiting."
    exit 1
fi

log=$(docker inspect -f '{{.LogPath}}' $1 2> /dev/null)
truncate -s 0 $log

Setup rotate Docker log

# if run docker run
docker run --log-opt max-size=10m --log-opt max-file=5 my-app:latest

# with docker-compose
my-app:  
    image: my-app:latest  
    logging:  
        driver: "json-file"  
        options:  
            max-file: 5  
            max-size: 10m

Ref:


Reactions: