To check the logging configuration used by docker, we can use docker system info
or docker info [1]:
# docker system info --format '{{.LoggingDriver}}'
json-file
The installation default is the json-file logging driver[4],
this means Docker captures stdout (and stderr) of the containers, and
writes them in JSON files
(can be found in /var/lib/docker/<container-id>/<container-id>-json.log)
The json-file driver default configuration is to use a single log file
of unlimited size. In order to change this default, we can add
logging driver configuration options to /etc/docker/daemon.json file (ref.
[3])
For example, to set a max file size, rotate, and compress:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "20m",
"max-file": "10",
"compress": "true"
}
}
From [4]:
Restart Docker for the changes to take effect for newly created containers. Existing containers do not use the new logging configuration."