Wednesday, October 26, 2016

Truncate or empty all docker container logs



After a while of dockering you'll have too much in your logs.  This command:

docker-compose logs -f 

Will take ages to show anything recent.  So you'll want to truncate those logs.

First run docker info to find where your docker logs are kept.  Example:

~/docker $ docker info
Containers: 68
 Running: 7
 Paused: 0
....
....
Docker Root Dir: /var/lib/docker

The docker root dir: is where you'll search.  Alternatively, use this command to see the docker root dir:

docker info | grep "Docker Root Dir: " | awk '{print $NF}'

This command should truncate all the docker logs to zero length.

sudo truncate -s 0 $(sudo find /var/lib/docker/containers/ -name "*-json.log")

To view the total bytes used by logs files:


sudo find /var/lib/docker/containers/ -name "*-json.log" -exec du -ch {} + | grep total$



No comments:

Post a Comment