Limit docker logs size

November 6, 2020

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'
            driver: "json-file"
                max-size: "100m"
                max-file: "10"

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:

Note: You can directly configure the logs at the docker daemon level. Checkout out here:

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!