Docker logging drivers and log rotation explained
A Docker logging driver decides where a container's stdout and stderr go, and json-file, the default, keeps them on disk without rotation unless you set limits.
- Updated Nov 27, 2026
- Markdown
Pick a logging driver, set size limits globally or per container, and verify which settings a container actually uses.
- Docker Engine on a Linux server with sudo
- At least one running container
A logging driver is the part of Docker that receives each container’s stdout and stderr and stores or ships them. The default, json-file, writes one JSON file per container on the host and does not rotate it unless you set max-size and max-file. On a busy service that file grows until the disk is full. Choose a driver, set limits in daemon.json or per container, and recreate containers so the settings apply.
How it works#
Containers should write logs to stdout and stderr, not to files inside the container. The Docker daemon captures those streams and hands them to the configured log driver. The driver decides the storage: a file on disk, the systemd journal, a syslog server or nowhere at all. You read the output with docker logs, covered in read container logs, when the driver keeps a readable local copy.
Settings are chosen per container at creation time, with daemon-wide defaults filling in anything you do not specify.
The common drivers#
json-file: the default. One JSON file per container under/var/lib/docker/containers/<id>/.docker logsworks. Options includemax-sizeandmax-file.local: a compact internal format designed to use less disk. It rotates by default with sensible limits, anddocker logsworks. The files are not meant to be read directly.journald: sends logs to the systemd journal, so you can usejournalctlwith container fields.docker logsworks. See read logs with journalctl.syslog: sends to a syslog daemon, local or remote. Good for central collection, butdocker logsmay not work.none: discards logs.docker logsreturns nothing. Use it only when you really do not want output.
Other drivers exist for specific log services, and some need their own plugins. Check Docker’s documentation before relying on one.
Step 1: See what you have now#
Check the daemon default:
docker info --format '{{.LoggingDriver}}'That prints the default driver, usually json-file. Then check one container:
docker inspect --format '{{.HostConfig.LogConfig}}' webThe output shows the driver type and any options, for example {json-file map[max-file:3 max-size:10m]}. If the map is empty, no limits are set and the log can grow without bound.
Step 2: Set limits for all new containers#
Edit the daemon config. Be careful to merge with any existing keys in the file, since invalid JSON stops Docker from starting:
sudo nano /etc/docker/daemon.jsonAdd:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}This keeps at most three files of 10 megabytes each per container. Choose values that fit your disk and how far back you need logs. Validate the JSON, then restart Docker:
sudo python3 -m json.tool /etc/docker/daemon.json
sudo systemctl restart dockerWarning: restarting the Docker daemon stops running containers unless live-restore is enabled, and containers with a restart policy come back afterward. Do it in a quiet window. Existing containers keep their old log settings. Only containers created after the restart use the new defaults, so recreate them (for Compose, docker compose up -d --force-recreate).
Step 3: Set limits per container or in Compose#
With docker run:
docker run -d --name web \
--log-driver json-file \
--log-opt max-size=10m --log-opt max-file=3 \
nginxIn Compose:
services:
web:
image: nginx
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"Per-container settings override the daemon defaults. Putting limits in the Compose file means the safety travels with the project. A shorter walk-through of this exact fix is in limit Docker log size.
Step 4: Consider the local or journald driver#
To switch the default to local, set "log-driver": "local" in daemon.json. It rotates on its own and is a good low-effort default if you only read logs through docker logs. For journald, set "log-driver": "journald" and query with journalctl CONTAINER_NAME=web. Journald’s own size limits are set in the journal configuration, not in Docker. Do not assume a particular retention without checking journalctl --disk-usage.
Check it worked#
Recreate a container and inspect it:
docker inspect --format '{{.HostConfig.LogConfig}}' webYou should see your driver and options. Then confirm that logs are still readable:
docker logs --tail 20 webTo find big existing logs, list file sizes with sudo du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail. Do not delete or truncate these files while a container runs without a plan. The safe cleanup is to recreate the container with limits set, which gives it a fresh log file. See check disk, memory and CPU usage to watch the disk itself.
Edge cases and gotchas#
- New containers only: Changing
daemon.jsondoes not touch running containers. Recreate them, not just restart them. - Rotation is per container:
max-sizeandmax-fileapply to each container separately, so total usage is containers times size times files. - Compression: The
compressoption rotates files into compressed form for json-file, which helps disk use but adds a little CPU work. - docker logs and drivers: With drivers that forward logs away,
docker logsmay fail or show nothing, even though logs are arriving elsewhere. - Dual logging: Newer Docker versions can keep a local readable cache for remote drivers, but check the documentation for your version before depending on it.
- App-side files: Logs the app writes to files inside the container are not seen by any driver and are not rotated by Docker.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Docker will not start after editing daemon.json | Invalid JSON or unknown key | Validate with json.tool, fix, restart, check journalctl -u docker |
| Old container still has no limits | Created before the change | Recreate the container |
| Disk keeps filling with *-json.log files | No max-size or max-file set | Set limits and recreate containers |
| docker logs shows nothing | Driver is none or a remote driver | Switch to json-file, local or journald, or read logs at the destination |
| Limits in Compose seem ignored | Container not recreated | Run docker compose up -d —force-recreate |
Quick reference#
docker info --format '{{.LoggingDriver}}'
docker inspect --format '{{.HostConfig.LogConfig}}' web
docker logs --tail 50 -f web
sudo systemctl restart docker
docker compose up -d --force-recreateRelated lessons#
- Limit Docker log size for the quick version of the rotation fix.
- Read container logs for filtering and following output.
- Read logs with journalctl if you use the journald driver.
- Free disk space with docker prune safely for other Docker disk use.
- Docker Compose basics for the logging key in a project file.
Next#
Continue with limit Docker log size.
Check what you learned
Frequently asked questions
How do I stop Docker logs from filling my disk?
Set max-size and max-file for the json-file driver in /etc/docker/daemon.json, or per container. Then recreate containers so they pick up the limits.
What is the default Docker logging driver?
json-file. It writes each container's output to a JSON file on the host, and by default it never rotates.
What is the difference between json-file and local drivers?
The local driver is a more compact format that rotates by default, so it is easier on disk. json-file is human-readable JSON but needs size limits you set yourself.
Why does docker logs show nothing with my logging driver?
The driver may not support reading. Drivers that ship logs to another system, such as syslog to a remote host, may leave docker logs empty or erroring.
Sources
Keep going: guides and tutorials
- Deploy a Docker Compose App Self-Hosted: Web, Redis and Rollback Deploy a Docker Compose app on your own server with Levelrail: a web service and Redis, a bad release that does not take traffic, and a compose rollback.
- Docker Container Restarting in a Loop: 5 Causes, Fixed Five real reasons a Docker container keeps restarting, each reproduced with its exit code, the command that finds it and the fix. Then the same crash on Levelrail.
- Deploy an Express App to a VPS With Docker and Health Checks Deploy a Node.js Express API to your own server with no Dockerfile. Covers the port rule, a health route, secrets, deploy failure codes and rollback.