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.

  1. 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, 
    1. max-size corresponds to the maximum file size before docker will switch to another file
    2. max-file corresponds to how many log files will exist

    More information about other tags is located here:

  2. echo 'DOCKER_OPTS="--config-file=/etc/docker/daemon.json"' > /etc/default/docker
  3. 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:

  • No labels