DEV Community

François
François

Posted on • Originally published at blog.lepape.me on

9 2

🐳 Limit docker logs size

Hello! The other day I got an alert on one server. The disk space was almost full, even though there is just a simple app controlled by a docker-compose.

It turned out one of the application was ElasticSearch, and the log file size of this container was... 10G.

So I had to find a way to remove and rotate the logs of this container.

Adding this part to the docker-compose.yml:

version: '3'
services:
    app:
        ...
        logging:
            driver: "json-file"
            options:
                max-size: "100m"
                max-file: "10"
Enter fullscreen mode Exit fullscreen mode

You can control how docker will deal with the logs: choose a log driver, the max size of the log file, and the number of files. Pretty convenient!

The official documentation here: https://docs.docker.com/compose/compose-file/#/logging

Note: You can directly configure the logs at the docker daemon level. Checkout out here: https://docs.docker.com/config/containers/logging/configure/#configure-the-default-logging-driver

To get further

Limit the log size on the system is great, but the best is to send the logs to a logs aggregator such as Loki or Elasticsearch!

Top comments (1)

Collapse
 
faakhy profile image
Rémy | FakeRunner

Right link for anchor is docs.docker.com/compose/compose-fi...

Thanks for this informations. Very useful.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up