DEV Community

bongo
bongo

Posted on

Limiting docker container's log size in CoreOS (running, but not limited to XenServer 7)

I had a problem: my gitlab docker container generated >6GiB of json-log (/var/lib/docker/containers/<ID>/*.json) filling up my disk.

I'm running CoreOS within a Citrix XenServer 7 with the Container Management Supplement Pack installed.

The way of configuring the Coreos VM is via /Cloud-Config/. There are multiple ways of configuring the docker service within CoreOS to set some global logging-driver options.

CoreOS' default driver is json-file with no limits. (as of dec. 2018)

  • Shutdown the CoreOS VM
  • Within XenCenter, edit the Cloudconfig as follows: To set up log-file limits to e.g. Maximum 60MiB/container and 1 logfile per container, insert below the write_files section:
write_files:
  - path: "/etc/docker/daemon.json"
    permissions: "0644"
    owner: "root"
    content: |
      {
        "log-driver": "json-file",
        "log-opts": {
          "max-size": "60m",
          "max-file": "1"
        }
      }
  • Start the VM again

IMPORTANT: Changes to this global setting are ONLY applied to newly created containers, so you'll need to re-setup every container you want to apply the setting to. If you don't, editing the hostconfig.json will not help, it's getting overwritten upon container restart.


Optional:

Verify file write worked:

cat /etc/docker/daemon.json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "60m",
    "max-file": "1"
  }
}

Verify container has applied the log settings (as root):
/var/lib/docker/containers//hostconfig.json

{"Binds":["/srv/gitlab/config:/etc/gitlab","/srv/gitlab/logs:/var/log/gitlab","/srv/gitlab/data:/var/opt/gitlab"],
"ContainerIDFile":"",
"LogConfig":{"Type":"json-file","Config":{"max-file":"1","max-size":"60m"}},
"NetworkMode":"public".....

See the IMPORTANT notice above, if this doesn't reflect the hostconfig you're seeing, regardig the LogConfig section.

Top comments (0)