Remove docker container logs

Posted on: December 4th 2019, 1:34:36 am

When a docker container is up for a long time its logs are sometimes not deletd. The size of the log file can be more than 100gb.

  • Check which container has the biggest size
$ sudo du -h --max-depth=2 /var/lib/docker/containers/

this will check which container has a large size

  • Grab container id
$ CONTAINER=<paste id here>
  • Grab log file path
$log=$(docker inspect -f '{{.LogPath}}' $CONTAINER)

  • Empty log file
$ truncate -s 0 $log