Record every new journey

How to Clear Docker Logs and Activate Log Rotate

0 591

How to Clear Docker Logs and Activate Log Rotate

This note will guide you clear docker logs on a Docker container and activate log rotate to prevent disk getting full. If your system is getting 100% disk usage 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

Below are the 3 options to clear docker logs 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.


Option 2:

You can combine both commands in a single command. Use the following command to truncate the log file of the specified Docker container.


Read Also >>

Option 3:

Truncate the log files of all docker containers in your system.

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

For me is prefer to choose option 3 with a modification like below.


If you want to get the size of the logs


If just to get the total of the size of the logs


Activate Log Rotate in Docker Logs

Log rotate is a system utility that manages the automatic rotation and compression of log files. If log files were not rotated, compressed, and periodically pruned, they could eventually consume all available disk space on a system.

Example file in /etc/logrotate.d/docker-logs


create config above and your docker logs will be rotate every week.

You might also like
Leave A Reply

Your email address will not be published.