DEV Community

Sergey Shinder
Sergey Shinder

Posted on

We capped Docker's log size in daemon.json and our gateway's disk kept filling for another week

One of our carrier gateways is a single VM running Docker Compose: an SFTP receiver for inbound files, a label adapter, and a small queue. In October the root filesystem reached a hundred percent, and the SFTP receiver started refusing uploads from two carriers because it could not write them.

The space was in /var/lib/docker/containers, in one file: the label adapter's container log, thirty eight gigabytes. Docker's default logging driver is json-file, and by default json-file never rotates. Every line a container writes to stdout is kept until the container is removed. The adapter logged each request body at info level, and it had been running since April.

We did what every guide says. We added log-opts to /etc/docker/daemon.json with max-size of fifty megabytes and max-file of five, restarted the Docker daemon, and freed space by moving old inbound files off the disk. A week later the disk was at ninety two percent and climbing.

docker inspect showed why. The adapter's HostConfig.LogConfig was still json-file with no options at all. A container's logging configuration is fixed when the container is created, and the defaults in daemon.json only apply to containers created after the daemon reads them. Docker's documentation says this in one sentence. Restarting the daemon brought the containers back up, and starting is not creating, so the adapter carried on under the settings it had been born with in April.

docker compose up -d with --force-recreate replaced all three containers, which removed the old log with the old container and gave the new ones their limits. We then moved the setting into the Compose file itself, with the local logging driver, which rotates and compresses by default, so the limit is in the repository and visible in review rather than in a file on one host. A check after each deploy compares every running container's LogConfig with what the Compose file declares. The adapter now logs request bodies only at debug level, and the filesystem alert fires at eighty percent.

One more detail cost us twenty minutes: the values in log-opts must be strings. Written as a number, max-file stops the daemon from starting at all.

We had changed the default. Everything already running had been created before there was one.

– Sergey Shinder

Top comments (0)