brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the local log driver keeps Docker logs compressed and rotated by default

Docker
~/tips/tip-docker-local-log-driver

docker run -d --log-driver local --name web nginx:alpine

Switch to Docker's local log driver for smaller logs that rotate on their own.

The default json-file driver keeps every log line forever unless you set limits. The local driver rotates and compresses out of the box, and docker logs keeps working.

docker run -d --log-driver local --name web nginx:alpine
docker inspect --format '{{.HostConfig.LogConfig.Type}}' web

According to the docs it keeps 100 MB per container by default, as five files of 20 MB, and stores them in a compact compressed format. You can change that with --log-opt max-size and max-file like with json-file.

To make it the default for every new container, set it in /etc/docker/daemon.json and restart Docker:

{
  "log-driver": "local"
}

Existing containers keep the driver they were created with, so recreate them to switch. I would check the current default with docker info --format '{{.LoggingDriver}}'.

The files are in an internal format. Tools that read json-file logs straight from /var/lib/docker/containers, such as some log shippers and Promtail setups, will not understand them. If you collect logs that way, stay on json-file and give it size limits instead.

Further reading: Local file logging driver, Configure logging drivers

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link