Bobcares

Install Logrotate in Docker Container

by | Jul 15, 2022

Installing logrotate in the docker container will allow the user to manage large Docker log files effortlessly. 

Bobcares answers all questions no matter the size, as part of our Docker hosting Support

Let us take a look at installing logrotate in the docker container in detail.

What is Docker Logrotate

Logrotate is a tool that makes managing systems with lots of log files easier. It enables the log files to rotate, compress, delete, and sent automatically. Each log file will process on a daily, weekly, monthly, or on a basis depending on its size. A user can use yum or dnf to install docker-logrotate on CentOS 7.

Install docker-logrotate on CentOS 7 Using yum

Firstly, Use yum to run the following command to update the yum database.

sudo yum makecache

sudo yum -y install docker-logrotate

Install docker-logrotate on CentOS 7 Using DNF

If the user does not already have DNF installed, they must do so first. Use the following command to update the yum database dnf.

sudo dnf makecache

After updating the yum database, we can use dnf to install docker-logrotate by performing the following command:

sudo dnf -y install docker-logrotate

Uninstall docker-logrotate on CentOS 7

To remove only the docker-logrotate package, use the following command:

sudo dnf remove docker-logrotate

CentOS 7 docker-logrotate Package Contents

/etc/cron.daily/docker-logrotate
/usr/share/doc/docker-logrotate-1.13.1
/usr/share/doc/docker-logrotate-1.13.1/README.docker-logrotate

Install and Enable Logrotate in Docker Containers

When the docker service is in a halt or a stop, open the text editor. And open the file that the docker service will need for the logrotate procedure. The user may select between editors such as nano, pico, and vim.

sudo vim /etc/docker/daemon.json

Then, in this file, insert the following lines and save and close the file. {
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}

After the process restarts the docker service. Use the following command to restart the docker service:

sudo systemctl restart docker

The user’s docker service has now begun to cycle logs in the “/var/lib/docker/containers/CONTAINERID/” directory. This is how to perform ‘install logrotate in docker’ container process.

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude, installing logrotate in the docker container is an easy process. And will help the user to rotate and manage their log files effectively. Installing the docker might create a big amount of logs because of the containers running in the background. The logrotate will help to manage the docker container logs effectively.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.