Docker’s default logging is the kind of default I’d never have picked: every line a container prints goes into one file that never rotates. On a box that runs for months, one chatty container can quietly fill the disk. I run a pile of containers on my Unraid server, so this is exactly the thing I’d want capped before it bites. Here’s how I’d find the culprit and set a limit, in about ten minutes.
- Time
- 4 min
- Steps
- 6
- Updated
- 26 Nov 2026
You will learn
- See where the space went
- Free space right now (optional)
- Set a limit for every new container
- Recreate the containers you already…
- Check that it worked
What you need
A Linux host with Docker Engine and sudo rights. I checked the commands below against the current Docker docs. Containers use the json-file logging driver unless you changed it, and that driver has no size limit by default: max-size is unlimited and max-file defaults to 1. Nick Janetakis wrote this up years ago in Docker Tip #69, and it is still true. He also points out that removing a container removes its logs, so the problem hits long-lived containers hardest. Nothing goes wrong for months, and then everything does.
Step 1 of 6: See where the space went
My advice is to look before you touch anything. First check how full the disk is and how much Docker thinks it uses.
df -h /var/lib/docker
docker system df
Matthieu from Virtua.Cloud suggests then looking for the biggest log files directly. Each container has one called <id>-json.log:
sudo du -ah /var/lib/docker/containers/ | sort -rh | head -10
The folder name is the container ID. Match it with docker ps --no-trunc to see which container it is.
If the biggest file belongs to a container you forgot about, stopping and removing it also removes its log. I’d call that the cleanest fix of all.
Step 2 of 6: Free space right now (optional)
If the disk is nearly full, empty the big file. This is a stopgap: the log history of that container is gone, and the file just grows again until you do step 3. I’d only do it for a file you identified in step 1.
sudo truncate -s 0 /var/lib/docker/containers/<id>/<id>-json.log
Do not delete the file with rm while the container runs. Docker keeps it open, so the space is not freed.
Step 3 of 6: Set a limit for every new container
Edit /etc/docker/daemon.json. If the file already exists, merge these keys into it instead of replacing it.
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
That caps one container at roughly 30 MB of logs. Two details trip people up. All values in log-opts must be strings, so the quotes around 3 are not optional. And max-file does nothing unless max-size is set too.
A typo in this file stops Docker from starting, so I’d validate it first, then restart. Restarting the daemon stops your containers unless live-restore is on, so pick a quiet moment.
python3 -m json.tool /etc/docker/daemon.json
sudo systemctl restart docker
Step 4 of 6: Recreate the containers you already have
The new default only applies to containers created after the change. The Docker docs say it plainly: existing containers do not pick it up. With Compose, recreate them from the project folder:
docker compose up -d --force-recreate
Recreating is safe for data in volumes and bind mounts. Anything a container wrote inside its own filesystem is lost, so check that first if you are unsure.
Step 5 of 6: Check that it worked
Ask the container itself, not the daemon:
docker inspect --format '{{.HostConfig.LogConfig}}' <container>
You should see json-file and your max-size and max-file values. If the options are empty, that container was created before the change.
Step 6 of 6: A noisy service gets its own limit
The global default is a safety net. For one service that logs a lot, I’d set it in the Compose file, which overrides the daemon default:
services:
app:
image: example/app
logging:
driver: json-file
options:
max-size: "5m"
max-file: "2"
Rotation also means old lines disappear. If you need history, send logs to something else (the local or journald drivers, or a log collector) instead of just raising the numbers.
Further reading
- Nick Janetakis: Docker Tip #69
- Virtua.Cloud: Docker Log Rotation
- Docker docs: JSON File logging driver
- Docker docs: docker system df
- On this site: Let Jellyfin in Docker use your Intel iGPU for transcoding
- On this site: When Prowlarr refuses to sync an indexer to Sonarr or Radarr, check these four things
- On this site: The Bazarr settings that matter, from languages to the minimum score
