This tutorial will help you clear the log file on a Docker container. If your system is getting out of disk space and you found that the docker container’s log files are consuming high disk space. you can find the log file location and clear them with the help of this tutorial. While clearing log files of a docker container, you don’t need to stop it.
Clear Docker Container Log File
First of all, find the log file location of a Docker container. Use inspect option to find the log file name and location.
docker container inspect --format='{{.LogPath}}' [CONTAINER ID/NAME]
Once you find the log file location, just truncate it with the following command.
truncate -s 0 /path/to/logfile
Here
-s
is used to set the size of a file. You provided 0 as input, which means completely truncate the log file.How to find Docker Container ID/NAME
Use the following command to view all containers including stopped containers. Remove
-a
command line parameter to list running containers only.docker container ps -a
You can also use sort command
docker ps -a
to view the same results.
1 Comment
oneline:
docker inspect –format='{{.LogPath}}’ | xargs truncate -s 0