DEV Community

Aidas Petryla
Aidas Petryla

Posted on

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