This page details how to setup up Docker to use a default configuration file with instructions on how to perform log rotation.
The following instructions were done from a fresh instance of centos and Docker.
- create the file /etc/docker/daemon.json with contents
{
"log-driver": "json-file",
"log-opts": {
"max-size": "1m",
"max-file": "6"
}
}
As the json keys may indicate,- max-size corresponds to the maximum file size before docker will switch to another file
- max-file corresponds to how many log files will exist
More information about other tags is located here:
https://docs.docker.com/engine/admin/logging/json-file/#usage echo 'DOCKER_OPTS="--config-file=/etc/docker/daemon.json"' > /etc/default/docker
Restart the docker service
service docker restart
Logging should now be active and paginated in/var/lib/docker/containers/<container id>/<container id>-json.log
An example python script and Dockerfile for proof of concept is located here:
https://github.com/c1mckay/DockerLogTest