Logs are essential for monitoring and debugging containers, but without proper rotation, they can grow uncontrollably and take up unnecessary disk space. If you use Podman, configuring log rotation is crucial to maintaining an efficient environment.
In this article, you will learn how to configure log rotation effectively in both Podman.
🚀 Why Is Log Rotation Important?
Without control, log files can grow indefinitely, impacting performance and even crashing the system due to a lack of disk space. Log rotation allows you to define a maximum log file size and the number of stored log files before automatic deletion.
🛠 Configuring Log Rotation in Podman
If you use Podman, the process is similar to Podman, but the configurations are made in the containers.conf
file.
1️⃣ Edit the Configuration File
Open the /etc/containers/containers.conf
file:
sudo vim /etc/containers/containers.conf
Add or modify the following lines in the [containers]
section:
[containers]
log_driver="json-file"
log_size_max=500000000
log_rotate_max=3
2️⃣ Restart Podman
sudo systemctl restart podman
Now, container logs in Podman will also have a 500MB limit, with a maximum of 3 log files per container.
🔍 How to Verify the Configuration?
After applying the configuration, you can check if everything is correctly set up.
Podman:
Confirm if the configuration is applied:
podman info | grep "log"
List log files:
ls -lh \
~/.local/share/containers/storage/overlay-containers/*/userdata/ctr.log
💡 Who Am I?
I am Gabriel Carmo, passionate about technology (especially Open Source). I have experience in Cloud, Kubernetes, OpenShift, Zabbix, Dynatrace, and more! Always exploring new technologies and sharing knowledge. 🚀
📬 Let's Connect?
🔗 LinkedIn
🐙 GitHub
🦊 GitLab
🏅 Credly
📧 Contact: contato@gabrielandre.com.br
