Docker by default does not limit the log file size, a small docker at my company runs over a year and accumulates 70Gb of log and blows up our disk. Instead of deleting the log file and doing some magic tricks, you should always keep the log file small. I list below some method to keep your Docker’s log managable.
-
If you use
docker-cli
, add --log-opt to yourdocker run
command:
--log-opt max-size=10m --log-opt max-file=5
-
If you use
docker-compose
, add the logging configuration:
<service_name>
logging:
max-size: "10m"
max-file: "5"
- If you are lazy, you can add the default logging configuration to the Docker daemon
/etc/docker/daemon.json
, but make sure to setup for a new machine:
{
"log-opts": {
"max-size": "10m",
"max-file": "5"
}
}