DEV Community

Aidas Petryla
Aidas Petryla

Posted on

8 1 1 1 2

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. :)

Top comments (2)

Collapse
 
watcharasukka profile image
Watchara Sukka

Can config using docker-compose?

Collapse
 
apetryla profile image
Aidas Petryla

Great question! I haven't tried myself, but from docker docs it appears that there should be such possibility: docs.docker.com/compose/compose-fi...

Let me know if it works for You! :)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay