Clear Docker Container Log File

Below are the 3 different options to clear log files of Docker containers. Choose any one of the below options to truncate the docker container log files. Some of the below options require a container id or name, which can be found with the docker ps -a command.

Option 1: In this option, first we will find the log file path and then truncate it. Use inspect option to find the log file name and location of a docker container.

As a result, you will get a log file path. Now truncate the log file with the following command. Here -s is used to set the size of a file. You provided 0 as input, which means completely truncating the log file.

You can quickly truncate the docker log files using one of the above options.

Wrap Up

In this blog post, you have learned to truncate (clear) log files of a Docker container.