A container that prints one line of text per request can fill a disk without anyone noticing, because by default Docker keeps every line it ever printed. In a test, one small container wrote 300,000 short lines and left a 40 MB log file behind, more than double the size of the text itself, with no limit in sight. A second container with two extra options wrote the same output and kept 2 MB. The tests below ran on a Docker daemon in an Ubuntu 24.04 sandbox using a minimal busybox image, and the figures are measured, not estimated.
Where container logs go
The default driver
Everything a container writes to standard output and standard error goes to a logging driver. On the test daemon, docker info reported json-file, and both test containers showed it in their configuration:
$ docker inspect -f '{{json .HostConfig.LogConfig}}' lg1
{"Type":"json-file","Config":{}}
The empty Config is the important part. No options means no limits.
One JSON object per line
The json-file driver stores each line as a small JSON object in a file under /var/lib/docker/containers/<id>/:
{"log":"log line 0 padding padding padding padding padding padding\n","stream":"stdout","time":"2026-12-01T05:02:41.267094551Z"}
The original line was 64 bytes. With the stream name and a nanosecond timestamp wrapped around it, it took about 134 bytes on disk. That is why the test log came out at 40,055,320 bytes for roughly 19 MB of actual text: about 2.1 times the original.

The test: unlimited versus capped
Two containers, same output
Both containers ran the same shell loop, printing 300,000 numbered lines and then sleeping. The first had no logging options. The second was started with:
docker run -d --name lg2 --log-opt max-size=1m --log-opt max-file=3 localbase:1 sh -c '...'
What was left on disk
== lg1
-rw-r----- 40055320 ...-json.log
== lg2
-rw-r----- 52214 ...-json.log
-rw-r----- 1000126 ...-json.log.1
-rw-r----- 1000105 ...-json.log.2
The capped container rolled its log every time it reached about 1 MB and kept three files: the current one and two older ones. Everything older was deleted. The uncapped container kept one ever-growing file.
What docker logs could still show
docker logs lg1 returned all 300,000 lines. docker logs lg2 returned 15,330, the first being line 284,670. The cap trades history for disk space, and the trade is real: anything that scrolled out of those three files is gone.
The two options
max-size and max-file
Docker’s documentation for the json-file driver describes max-size as the maximum size of the log before it is rolled, written as a number with k, m or g, and says it defaults to -1 (unlimited). max-file is the number of log files that can exist; when rolling creates too many, the oldest is removed. The same page notes that max-file only takes effect when max-size is also set, so setting it alone does nothing.
The worst case per container
The disk a container’s logs can use is roughly max-size × max-file. With the documentation’s own example of 10m and 3, that is about 30 MB per container. Twenty containers on a home server would cap out near 600 MB, a number that is easy to plan for. Unlimited has no such number.
How fast an uncapped log grows
The test’s own figure, about 134 bytes on disk per 64-byte line, makes the growth easy to project. At a steady rate of lines per second, an uncapped json-file log grows by:
| Lines per second | Per day | Per 30 days |
|---|---|---|
| 1 | 11.5 MB | 0.35 GB |
| 10 | 115 MB | 3.5 GB |
| 100 | 1.15 GB | 34.6 GB |
| 1,000 | 11.5 GB | 346 GB |
A web app logging every request at a modest 10 requests a second is a few gigabytes a month. A chatty debug setting left on at 1,000 lines a second fills a typical small SSD in weeks. Longer lines grow faster still.
Compression saves disk, not history
The json-file driver also has a compress option for rotated files, which the documentation says defaults to false. A fourth container ran the same loop with max-size=1m, max-file=3 and compress=true:
-rw-r----- 52746 ...-json.log
-rw-r----- 56963 ...-json.log.1.gz
-rw-r----- 56769 ...-json.log.2.gz
Each rotated megabyte shrank to about 57 KB, because repetitive log text compresses extremely well. But docker logs returned 15,333 lines, essentially the same as the uncompressed container. The limit is counted on the uncompressed file before it is rolled, and the number of files kept does not change. Compression frees disk space; it does not keep more history. To keep more, raise max-size or max-file, and let compression make the bigger setting cheap.

Setting a default for every container
daemon.json
Per-container flags are easy to forget. A default for the whole daemon goes in /etc/docker/daemon.json, and the json-file page gives this example:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
The documentation notes that values in log-opts must be strings, so "3" needs its quotes even though it is a number.
The catch: existing containers
That file was written on the test machine and the daemon restarted. A new container picked up the defaults at once:
/lg4 {"Type":"json-file","Config":{"max-file":"3","max-size":"10m"}}
The container created before the change did not:
/lg1 {"Type":"json-file","Config":{}}
Docker’s documentation says the same thing in plain words: restart Docker for the changes to take effect for newly created containers, and existing containers don’t use the new logging configuration automatically. Restarting a container is not enough; it keeps its original settings. It has to be removed and created again, which for Compose means docker compose up -d --force-recreate or a change that makes Compose recreate it.
Per service in Compose
The same options can also be written per service in a Compose file under a logging: key with driver and options, which keeps the limit next to the service that needs it and survives a move to another machine with a different daemon.json.
The local driver
Rotation and compression by default
Docker also ships a local logging driver. Its documentation says that by default it preserves 100MB of log messages per container and compresses them: five files of 20 MB each, with compression of rotated files enabled.
Tested
A third container wrote the same 300,000 lines with --log-driver local:
-rw-r----- 6217302 container.log
-rw-r----- 1293037 container.log.1.gz
About 7.3 MB on disk for the same output that took 40 MB as JSON, and docker logs still returned all 300,000 lines because the total had not reached its limit. Reading all of them back took 1.2 seconds. The trade-off is that the files are in Docker’s own format, not plain JSON, so other tools reading them directly will not understand them.

Cleaning up a log that is already huge
Finding it
Log files live inside each container’s directory, so sorting those directories by size shows the culprit quickly:
du -sh /var/lib/docker/containers/*/ | sort -h | tail -3
On the test machine, the uncapped container’s directory came out at 39 MB, next to 7.3 MB for the local-driver container and 2 MB for the capped one.
docker system df does not count it
docker system df looks like the natural place to check, but on the test machine it reported all containers together at 118.8 kB, while the container directories held several megabytes of logs. Its container figure is the containers’ writable layers, not their logs, so a log problem does not show up there. du on the containers directory is the reliable check.
Truncating, and the warning against it
A common quick fix is to empty the file in place with truncate -s 0. It worked in the test: afterward, docker logs lg1 returned zero lines and the space came back. But the json-file documentation carries a warning that these files are meant to be accessed only by the Docker daemon, and that touching them with external tools may interfere with Docker’s logging system. Truncating is an emergency measure to free a full disk. The lasting fix is recreating the container with a size limit, after which the problem cannot come back.
Removing the container removes the log
The log files live in the container’s own directory, so deleting the container deletes them. After docker rm -f lg2, its directory under /var/lib/docker/containers/ no longer existed. That is worth knowing before recreating a container to apply new limits: any log history needed for troubleshooting should be saved first with docker logs lg2 > lg2.log.
Turning logs off entirely
For a container whose output is worthless, such as a noisy helper that is monitored some other way, the none driver discards everything. A container started with --log-driver none had no log file at all in its directory, and docker logs refused with configured logging driver does not support reading. That is the right answer for very few containers, and the wrong one for anything that might ever need debugging.
Reading only the recent part
For a log that is large but not yet a problem, docker logs --tail 100 shows just the last lines instead of the whole file. The earlier post on Docker networking used the same test daemon and image.
Sources
- JSON File logging driver, Docker Docs: https://docs.docker.com/engine/logging/drivers/json-file/
- Local file logging driver, Docker Docs: https://docs.docker.com/engine/logging/drivers/local/
