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:
$ 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'$ docker run -d --name web nginx:alpineEvery container gets the log setting Docker had when it was created. On a stock install that is json-file with no options:
$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[]}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:
$ sudo du -sh /var/lib/docker/containers/*du: cannot access '/var/lib/docker/containers/*': No such file or directoryYour 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:
$ sudo sh -c 'du -sh /var/lib/docker/containers/*' | sort -rh | head -n 3107M /var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d40K /var/lib/docker/containers/34886ccfc21d82095c8cba7e500e773892b86fe9dedfb93ac091f379325ff547Twenty seconds was enough for tens of MB. To get the exact file of one container:
$ docker inspect -f '{{.LogPath}}' chatty/var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.logFree 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:
$ docker stop chatty$ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)"150 /var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.log$ sudo truncate -s 0 "$(docker inspect -f '{{.LogPath}}' chatty)"$ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)"0 /var/lib/docker/containers/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d/837f36ac300a5afd02895f131781eae8acf56f92f6377257f1c83488a51f1e9d-json.log$ docker start chattyFrom 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:
$ 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", }}$ 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--validate only reads the file: Docker kept running. The correct file, without that comma:
$ 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" }}$ sudo dockerd --validate --config-file /etc/docker/daemon.jsonconfiguration OKRestart Docker, and check your containers came back
$ sudo systemctl restart docker$ docker ps -a --format '{{.Names}}: {{.Status}}'web: Exited (0) 24 seconds agochatty: Up 14 secondschatty is back; web, started without a restart policy, is still down. Start it by hand:
$ docker start webRecreate 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:
$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[]}Remove it and create it again with the same command:
$ 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'$ docker inspect -f '{{.HostConfig.LogConfig}}' chatty{json-file map[max-file:3 max-size:10m]}Check the limit holds
Forty seconds later the container had written about 100 MB of log. On disk:
$ 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$ sudo sh -c 'du -cm "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log* | tail -n 1'24 totalThree 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. Usesudo 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.jsonnames the problem. Details. - The log still grows after the change: the container was created before it.
docker inspect -f '{{.HostConfig.LogConfig}}' <name>showsmap[]; recreate it. Details. - A container is down after the restart: it has no restart policy. Start it, and give it
--restart unless-stoppednext 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:
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-30-generic | Ubuntu 24.04.4 LTS6.8.0-138-generic |
| docker-ce | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| docker-ce-cli | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| containerd.io | 2.4.2-4~ubuntu.26.04~resolute | 2.4.2-4~ubuntu.24.04~noble |
| Commands and results | The same on every release: the same commands, the same results. | |
| Proof | Run log, 20 checks passed | Run log, 20 checks passed |
Undo: remove the limit
$ docker rm -f web$ sudo rm /etc/docker/daemon.json$ sudo systemctl restart dockerweb