[This answer covers current versions of docker for those coming across the question long after it was asked.]
To set the default log limits for all newly created containers, you can add the following in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {"max-size": "10m", "max-file": "3"}
}
Then reload docker with systemctl reload docker
if you are using systemd (otherwise use the appropriate restart command for your install).
You can also switch to the local logging driver with a similar file:
{
"log-driver": "local",
"log-opts": {"max-size": "10m", "max-file": "3"}
}
The local logging driver stores the log contents in an internal format (I believe protobufs) so you will get more log contents in the same size logfile (or take less file space for the same logs). The downside of the local driver is external tools like log forwarders, may not be able to parse the raw logs. Be aware the docker logs
only works when the log driver is set to json-file
, local
, or journald
.
The max-size
is a limit on the docker log file, so it includes the json or local log formatting overhead. And the max-file
is the number of logfiles docker will maintain. After the size limit is reached on one file, the logs are rotated, and the oldest logs are deleted when you exceed max-file
.
For more details, docker has documentation on all the drivers at: https://docs.docker.com/config/containers/logging/configure/
I also have a presentation covering this topic. Use P
to see the presenter notes: https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#logs
--log-driver=none
. If you want to disable logs only for specific containers, you can start them with--log-driver=none
in thedocker run
command. Another option could be to mount an external storage to/var/lib/docker
. Like an NFS share or something which has more storage capacity than the host in question. – Estuarinejournald
log driver, and have journald worry about log rotation. – Geilich/usr/lib/systemd/system/docker.service
might be the file. I am not sure on CoreOS. On CentOS, that's the location. As for other question is concerned, you need to change Docker daemon's options to usejournald
as logging driver. Then it'll log containers using journald and not log to/var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log
. @Geilich correct me if I am missing something. – Estuarine