Docker log rotation

Today, I deleted 130 GB of logs. I don’t know who started those Docker containers, but let me share a valuable concept: log rotation.

For example, one can define it in daemon.json:

{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3", }
}
Enter fullscreen mode
Exit fullscreen mode

or directly when starting a container:

docker run \ --log-driver=json-file \ --log-opt max-size=10m \ --log-opt max-file=3 \ my-image
Enter fullscreen mode
Exit fullscreen mode

or even as an Ansible script:

- name: Start Grafana loki docker_container: name: my-container image: my-image state: started log_driver: json-file log_options: max-size: "10m" max-file: "3"
Enter fullscreen mode
Exit fullscreen mode

There’s no need to store 130 GB of logs. Really. 🙂


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

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

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Tag archives : fright night 2 2013 wiki. Blog slider home. * add your javascript code here.