Skip to content

Logging drivers and log rotation

Select an icon to see what it is.

Step 6 of 6

A host-wide default in daemon.json

To set limits for every new container, put log-driver and log-opts in /etc/docker/daemon.json and restart dockerd. Containers that already exist keep the driver they were created with. docker info shows the current default.

$ docker info --format '{{.LoggingDriver}}'
PrevNext

/etc/docker/daemon.json

{
"log-driver": "local"
"log-opts": {
"max-size": "10m"
"max-file": "3"
}
}

Try it yourself

Make a container log a lot with a tiny size limit, and look at the rotated files.

$ docker run -d --name chatty --log-opt max-size=1k --log-opt max-file=3 alpine sh -c 'yes hello | head -n 1000'
$ sleep 2
$ sudo ls -l $(dirname $(docker inspect --format '{{.LogPath}}' chatty))
$ docker logs chatty | wc -l
$ docker info --format '{{.LoggingDriver}}'
$ docker rm -f chatty

Quiz

1. What happens to json-file logs if you set no limits?
2. Where does dockerd get a container's log lines?
3. Do existing containers pick up a new default in daemon.json?