With Docker’s default json-file logging, a chatty container can fill a disk with its own log. Two options stop that.
The Docker docs say max-size defaults to -1, which means unlimited, so nothing rotates until you set it. The other option, max-file, is the number of log files to keep. It defaults to 1 and only has an effect when max-size is set. Per container:
docker run -d --log-opt max-size=10m --log-opt max-file=3 <image>
That rolls the log at 10 megabytes and keeps at most three files, deleting the oldest, so one container’s log stays around 30 megabytes at most. The size takes a unit of k, m or g. There is also compress, off by default, for the rotated files. In a Compose file the same settings go under the service:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
To set it for all containers, put it in /etc/docker/daemon.json under log-opts. The docs say the values must be strings, so the number in max-file gets quotes too. Restart Docker afterwards.
Existing containers do not pick up a changed daemon config. The docs say it applies to newly created containers, so recreate the old ones to get the limit.
Further reading: Docker docs: JSON File logging driver