Short answer

Docker’s default log driver keeps every line a container prints, with no limit. Set "log-opts": {"max-size": "10m", "max-file": "3"} in /etc/docker/daemon.json, check it with sudo dockerd --validate, restart Docker, then recreate your containers: existing ones keep the old, unlimited setting. To free space now, stop the container and truncate -s 0 its log.

Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed

A container log with no limit

The test started a busy container that prints about 2.7 MB of log a second, and a quiet web server:

Server
$ docker run -d --name chatty --restart unless-stopped alpine sh -c 'while :; do head -c 100000 /dev/urandom | base64 -w 0; echo; sleep 0.05; done'
Server
$ docker run -d --name web nginx:alpine

Every container gets the log setting Docker had when it was created. On a stock install that is json-file with no options:

Server
$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[]}
Output hidden (1 line)

map[] means no size limit and no rotation: the file grows until the disk is full.

Find which container logs are big

The logs live in /var/lib/docker/containers/<id>/<id>-json.log, a folder only root may read. The command most people type fails:

Server
$ sudo du -sh /var/lib/docker/containers/*du: cannot access '/var/lib/docker/containers/*': No such file or directory
Output hidden (1 line)

Your own shell expands the * before sudo runs, and your user may not look inside the folder, so du gets a literal *. Let a root shell expand it:

Server
$ sudo sh -c 'du -sh /var/lib/docker/containers/*' | sort -rh | head -n 3107M	/var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d40K	/var/lib/docker/containers/34886ccfc21d82095c8cba7e500e773892b86fe9dedfb93ac091f379325ff547
Output hidden (2 lines)

Twenty seconds was enough for tens of MB. To get the exact file of one container:

Server
$ docker inspect -f '{{.LogPath}}' chatty/var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.log
Output hidden (1 line)

Free the space now: empty the log

Stop the container so nothing writes while you empty the file, empty it with truncate (the file stays, only its content goes), and start it again:

Server
$ docker stop chatty
Server
$ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)"150	/var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.log
Output hidden (1 line)
Server
$ sudo truncate -s 0 "$(docker inspect -f '{{.LogPath}}' chatty)"
Server
$ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)"0	/var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.log
Output hidden (1 line)
Server
$ docker start chatty

From many MB to 0, and docker logs keeps working with the new lines. The file starts growing again at once, though: the lasting fix is a limit.

The lasting fix: a log limit in daemon.json

/etc/docker/daemon.json sets Docker’s defaults. It does not exist on a stock install. max-size is the size of one log file before Docker starts a new one; max-file is how many it keeps. 10 MB × 3 = at most 30 MB per container.

A slip that is easy to make: a comma after the last item. The test wrote that first:

Server
$ printf '{\n  "log-driver": "json-file",\n  "log-opts": {\n    "max-size": "10m",\n    "max-file": "3",\n  }\n}\n' | sudo tee /etc/docker/daemon.json{  "log-driver": "json-file",  "log-opts": {    "max-size": "10m",    "max-file": "3",  }}
Output hidden (7 lines)
Server
$ sudo dockerd --validate --config-file /etc/docker/daemon.jsonunable to configure the Docker daemon with file /etc/docker/daemon.json: invalid JSON: invalid character '}' looking for beginning of object key string
Output hidden (1 line)

--validate only reads the file: Docker kept running. The correct file, without that comma:

Server
$ printf '{\n  "log-driver": "json-file",\n  "log-opts": {\n    "max-size": "10m",\n    "max-file": "3"\n  }\n}\n' | sudo tee /etc/docker/daemon.json{  "log-driver": "json-file",  "log-opts": {    "max-size": "10m",    "max-file": "3"  }}
Output hidden (7 lines)
Server
$ sudo dockerd --validate --config-file /etc/docker/daemon.jsonconfiguration OK
Output hidden (1 line)

Restart Docker, and check your containers came back

Server
$ sudo systemctl restart docker
Server
$ docker ps -a --format '{{.Names}}: {{.Status}}'web: Exited (0) 24 seconds agochatty: Up 14 seconds
Output hidden (2 lines)

chatty is back; web, started without a restart policy, is still down. Start it by hand:

Server
$ docker start web

Recreate existing containers: they keep the old setting

The new default only applies to containers created from now on. chatty was created before, and still has no limit:

Server
$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[]}
Output hidden (1 line)

Remove it and create it again with the same command:

Server
$ docker rm -f chatty$ docker run -d --name chatty --restart unless-stopped alpine sh -c 'while :; do head -c 100000 /dev/urandom | base64 -w 0; echo; sleep 0.05; done'
Server
$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[max-file:3 max-size:10m]}
Output hidden (1 line)

Check the limit holds

Forty seconds later the container had written about 100 MB of log. On disk:

Server
$ sudo sh -c 'ls -lh "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log*'-rw-r----- 1 root root 590K Nov 19 09:48 /var/lib/docker/containers/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396-json.log-rw-r----- 1 root root 9.6M Nov 19 09:48 /var/lib/docker/containers/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396-json.log.1-rw-r----- 1 root root 9.6M Nov 19 09:48 /var/lib/docker/containers/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396/776a0ae3cead94b8aee3563187c2d293a7918b416f65c436d65a78eb74954396-json.log.2
Output hidden (3 lines)
Server
$ sudo sh -c 'du -cm "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log* | tail -n 1'24	total
Output hidden (1 line)

Three files, the current one and two older ones (.1, .2), and never more than 3 × 10 MB together. The oldest lines are dropped as new ones come in, so docker logs shows only what fits.

Troubleshooting

  • du: cannot access '/var/lib/docker/containers/*': your shell expanded the *, not root’s. Use sudo sh -c 'du -sh /var/lib/docker/containers/*'. Details.
  • Docker will not start after editing daemon.json: the JSON is wrong. sudo dockerd --validate --config-file /etc/docker/daemon.json names the problem. Details.
  • The log still grows after the change: the container was created before it. docker inspect -f '{{.HostConfig.LogConfig}}' <name> shows map[]; recreate it. Details.
  • A container is down after the restart: it has no restart policy. Start it, and give it --restart unless-stopped next time. Details.

What these steps changed on the server

Both runs recorded the server before the first step and after the last (see the Tested on box below): the new /etc/docker/daemon.json, and the containers themselves, which live under /var/lib/docker.

Ubuntu 26.04 vs 24.04

The same check ran on a fresh 26.04 server and on a fresh 24.04 server, each with its own run log:

WhatUbuntu 26.04Ubuntu 24.04
SystemUbuntu 26.04.1 LTS7.0.0-30-genericUbuntu 24.04.4 LTS6.8.0-138-generic
docker-ce5:29.10.0-1~ubuntu.26.04~resolute5:29.10.0-1~ubuntu.24.04~noble
docker-ce-cli5:29.10.0-1~ubuntu.26.04~resolute5:29.10.0-1~ubuntu.24.04~noble
containerd.io2.4.2-4~ubuntu.26.04~resolute2.4.2-4~ubuntu.24.04~noble
Commands and resultsThe same on every release: the same commands, the same results.
ProofRun log, 20 checks passedRun log, 20 checks passed

Undo: remove the limit

Server
$ docker rm -f web$ sudo rm /etc/docker/daemon.json$ sudo systemctl restart dockerweb
Output hidden (1 line)