How to limit the docker log size?
Have you given a surprise after a month or two that all the space in your server is filled with docker logs? Do you know that if you don’t control the size of the log, it will also impact running containers?
These two problems can be resolved easily by configuring the docker container. It is preferred that you control each log size separately because some logs you don’t need much while some you do.
For instance, in case of Nginx/Apache you might want to keep more logs while for some less relevant applications like emailing, you might want to keep logs for only a few days.
version: "3.8" services: nginx: image: nginx logging: driver: "json-file" options: max-size: "20m" max-file: "30"
This will ensure that at max, you will have 30 files and each file size will be a maximum of 20 megabytes. You can use 20k for kilobytes