ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/docker-logs-filling-disk Check scripts/live/checks/docker-logs-filling-disk.mjs (sha256 4742f8e5dee505480259c7b0e73ee84e2279ab229659a2a829444ce756c1f54e) Ran at 2026-11-19T16:00:10Z (336 s) Result PASS, all 20 claims held Tested on System Ubuntu 24.04.4 LTS Kernel 6.8.0-138-generic Package docker-ce 5:29.10.0-1~ubuntu.24.04~noble Package docker-ce-cli 5:29.10.0-1~ubuntu.24.04~noble Package containerd.io 2.4.2-4~ubuntu.24.04~noble Setup A fresh Ubuntu 24.04 server (a rented cloud server, rebuilt to the provider’s stock image) with Docker Engine installed from Docker’s apt repository, as the install article leaves it, reached over SSH as the sudo user deploy (in the docker group). A test container writes about 2.7 MB of log a second. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (0) Packages upgraded (0) Packages removed (0) Services enabled at boot (0) Services disabled (0) Listening sockets opened (0) Listening sockets closed (0) Files added in /etc (1) /etc/docker/daemon.json Files changed in /etc (0) Files removed from /etc (0) Disk used on / (includes logs written during the run): +78.5 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Check-your-server script (2 items): https://cdn.serverhandbook.com/check/docker-logs-filling-disk/ubuntu-24.04.4-20261119t160010z.sh SHA-256 0a51d4ce3c323d5a0c742e6e932f70649fdccddf592e5ea4d573e855447bc2ba ------------------------------------------------------------------------------ On the stock server, before the first step: FAIL daemon.json sets a log size limit for new containers PASS every running container has a log size limit After the last step: PASS daemon.json sets a log size limit for new containers PASS every running container has a log size limit ------------------------------------------------------------------------------ Claims (20), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) Docker is installed and the docker group exists | docker:x:988: 3. ok (setup) a new login of deploy is in the docker group | deploy sudo users docker 4. ok LogConfig: {json-file map[]}: no limit | {json-file map[]} 5. ok sudo du -sh /var/lib/docker/containers/*: "cannot access '/var/lib/docker/containers/*'" | du: cannot access '/var/lib/docker/containers/*': No such file or directory 6. ok du: the chatty container folder is tens of MB after 20 seconds | 96M /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae | 40K /var/lib/docker/containers/f1bc4455b40a3b36874f3181af1e1ad4a535a5b6d83a7b5f3c1d68a39dc89af8 7. ok LogPath is /var/lib/docker/containers//-json.log | /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log 8. ok truncate -s 0 empties the log (tens of MB → 0) | 136 /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log | 0 /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log 9. ok docker logs still works after the truncate (new lines arrive) | 2265 10. ok dockerd --validate catches the trailing comma (and Docker keeps running) | unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid JSON: invalid character '}' looking for beginning of object key string 11. ok dockerd --validate: configuration OK | configuration OK 12. ok after the restart: chatty (unless-stopped) is Up, web (no restart policy) is Exited | web: Exited (0) 27 seconds ago | chatty: Up 16 seconds 13. ok the existing container still has no limit: {json-file map[]} | {json-file map[]} 14. ok the new container: {json-file map[max-file:3 max-size:10m]} | {json-file map[max-file:3 max-size:10m]} 15. ok three log files: -json.log, .1 and .2 | -rw-r----- 1 root root 6.8M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log | -rw-r----- 1 root root 9.6M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log.1 | -rw-r----- 1 root root 9.6M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log.2 16. ok all of them together: 31 MB or less after ~100 MB was written | 25 total 17. ok (daemon.json sets a log size limit at the end of the steps) | 1 18. ok (every running container has a log size limit at the end of the steps) | 0 19. ok (tested on) the box reports its OS, kernel and the version of 3 package(s) | PRETTY_NAME="Ubuntu 24.04.4 LTS" | VIRT=none | KERNEL=6.8.0-138-generic | PKG containerd.io 2.4.2-4~ubuntu.24.04~noble | PKG docker-ce 5:29.10.0-1~ubuntu.24.04~noble | PKG docker-ce-cli 5:29.10.0-1~ubuntu.24.04~noble 20. ok undo: daemon.json removed and Docker running again | web | active ------------------------------------------------------------------------------ Commands and what they printed (27) ------------------------------------------------------------------------------ $ 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' 85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae $ docker run -d --name web nginx:alpine Unable to find image 'nginx:alpine' locally alpine: Pulling from library/nginx c4f3d97811f6: Pulling fs layer 04c3905a997c: Pulling fs layer 4c8c172c6586: Pulling fs layer 61d8f4c85a74: Pulling fs layer 881fc932939e: Pulling fs layer 7cb374baf968: Pulling fs layer 77a3bfea78f5: Pulling fs layer 04c3905a997c: Pull complete 79979b969278: Download complete Digest: sha256:0563c36f94a6d3ec3584161b77859f740f7e20b4853f52c796a864ce6908e8ea Status: Downloaded newer image for nginx:alpine f1bc4455b40a3b36874f3181af1e1ad4a535a5b6d83a7b5f3c1d68a39dc89af8 $ docker inspect -f '{{.HostConfig.LogConfig}}' chatty {json-file map[]} $ sudo du -sh /var/lib/docker/containers/* du: cannot access '/var/lib/docker/containers/*': No such file or directory $ sudo sh -c 'du -sh /var/lib/docker/containers/*' | sort -rh | head -n 3 96M /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae 40K /var/lib/docker/containers/f1bc4455b40a3b36874f3181af1e1ad4a535a5b6d83a7b5f3c1d68a39dc89af8 $ docker inspect -f '{{.LogPath}}' chatty /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log $ docker stop chatty chatty $ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)" 136 /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log $ sudo truncate -s 0 "$(docker inspect -f '{{.LogPath}}' chatty)" $ sudo du -m "$(docker inspect -f '{{.LogPath}}' chatty)" 0 /var/lib/docker/containers/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae/85e1423c894dd96688793fb396018f28e785a7b9fc1798865a7ace111eeea9ae-json.log $ docker start chatty chatty $ docker logs --tail 1 chatty | wc -c 2265 $ 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.json unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid JSON: invalid character '}' looking for beginning of object key string $ 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.json configuration OK $ sudo systemctl restart docker $ docker ps -a --format '{{.Names}}: {{.Status}}' web: Exited (0) 27 seconds ago chatty: Up 16 seconds $ docker start web web $ docker inspect -f '{{.HostConfig.LogConfig}}' chatty {json-file map[]} $ 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' chatty a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de $ docker inspect -f '{{.HostConfig.LogConfig}}' chatty {json-file map[max-file:3 max-size:10m]} $ sudo sh -c 'ls -lh "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log*' -rw-r----- 1 root root 6.8M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log -rw-r----- 1 root root 9.6M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log.1 -rw-r----- 1 root root 9.6M Nov 19 16:04 /var/lib/docker/containers/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de/a77d0f548ecf5556a3b54dd38b866ca386b062b0771f15559ff6360d6f39e1de-json.log.2 $ sudo sh -c 'du -cm "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log* | tail -n 1' 25 total $ docker rm -f chatty chatty $ docker rm -f web $ docker run -d --name web --restart unless-stopped nginx:alpine web 9eccb5b8d0f84cd1d9b3dbf79d930fb6f9105cf66cda8bbc52b906aa15ecf59f $ docker rm -f web $ sudo rm /etc/docker/daemon.json $ sudo systemctl restart docker web ------------------------------------------------------------------------------ The check-your-server script, its full screen before the steps ------------------------------------------------------------------------------ ServerHandbook check, docker-logs-filling-disk (proved 2026-11-19) FAIL daemon.json sets a log size limit for new containers fix: https://serverhandbook.com/kb/docker-logs-filling-disk#daemon-json PASS every running container has a log size limit 1 passed, 1 failed To fix a FAIL, follow the steps in https://serverhandbook.com/kb/docker-logs-filling-disk ------------------------------------------------------------------------------ The check-your-server script, its full screen after the steps ------------------------------------------------------------------------------ ServerHandbook check, docker-logs-filling-disk (proved 2026-11-19) PASS daemon.json sets a log size limit for new containers PASS every running container has a log size limit 2 passed, 0 failed ------------------------------------------------------------------------------ The check's source (scripts/live/checks/docker-logs-filling-disk.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB fix: Docker container logs filling the disk. Docker's default json-file driver keeps every line forever. Steps: a * chatty container's log grows with no limit (LogConfig map[]); find the biggest logs; the emergency fix (truncate, * not rm: an rm'd log keeps its space while dockerd holds it); the lasting fix (log-opts in /etc/docker/daemon.json, * validated with `dockerd --validate` BEFORE the restart: a typo stops Docker from starting); a restart of Docker * leaves containers without a restart policy stopped; existing containers keep their old (unlimited) setting until * recreated; after recreating, the log stays within max-size × max-file. * * Runs on a fresh server; Docker Engine is installed first exactly as the install article does it (hidden). */ import { bareBox, reportBox } from '../lib.mjs' export const meta = { reader: [ { item: 'daemon.json sets a log size limit for new containers', cmd: "sudo grep -c '\"max-size\"' /etc/docker/daemon.json 2>/dev/null || true", expect: '^1$', step: 'daemon-json', }, { item: 'every running container has a log size limit', cmd: "docker ps -q | xargs -r docker inspect -f '{{index .HostConfig.LogConfig.Config \"max-size\"}}' | grep -c 'no value' || true", expect: '^0$', step: 'recreate', }, ], } const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const CODENAME = { '24.04': 'noble', '26.04': 'resolute' }[RELEASE] const INSTALL = [ `echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 >/dev/null`, 'sudo apt-get update -qq', 'sudo install -m 0755 -d /etc/apt/keyrings', 'sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc', 'sudo chmod a+r /etc/apt/keyrings/docker.asc', `printf 'Types: deb\\nURIs: https://download.docker.com/linux/ubuntu\\nSuites: ${CODENAME}\\nComponents: stable\\nArchitectures: amd64\\nSigned-By: /etc/apt/keyrings/docker.asc\\n' | sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null`, 'sudo apt-get update -qq', 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >/dev/null', ].join(' && ') // About 2.7 MB of log a second: 20 lines of 133 KB. const 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'` const MB = (s) => Number((s.match(/^(\d+)/m) ?? [])[1] ?? NaN) const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() L(INSTALL, 1800000) const grp = L('getent group docker') ctx.check('(setup) Docker is installed and the docker group exists', /^docker:x:\d+:/m.test(grp), grp) L('sudo usermod -aG docker $USER') const me = L('id -nG') ctx.check('(setup) a new login of deploy is in the docker group', /\bdocker\b/.test(me), me) L('sudo docker pull -q alpine', 600000) // ── 1. a log with no limit ────────────────────────────────────────────────────────────── run(CHATTY, { id: 'chatty' }) run('docker run -d --name web nginx:alpine', { id: 'web', timeout: 300000 }) L('sleep 20') const lc = run("docker inspect -f '{{.HostConfig.LogConfig}}' chatty", { id: 'logconfig-before' }) ctx.check('LogConfig: {json-file map[]}: no limit', /^\{json-file map\[\]\}$/m.test(lc.out), lc.out) // The glob is expanded by the user's shell, which may not list the root-only folder: du gets a literal "*". const glob = run('sudo du -sh /var/lib/docker/containers/*', { id: 'du-glob' }) ctx.check("sudo du -sh /var/lib/docker/containers/*: \"cannot access '/var/lib/docker/containers/*'\"", /cannot access '\/var\/lib\/docker\/containers\/\*'/.test(glob.out), glob.out) const du1 = run("sudo sh -c 'du -sh /var/lib/docker/containers/*' | sort -rh | head -n 3", { id: 'du-before' }) ctx.check('du: the chatty container folder is tens of MB after 20 seconds', /^\d+(\.\d+)?M\s/m.test(du1.out), du1.out) const lp = run("docker inspect -f '{{.LogPath}}' chatty", { id: 'logpath' }) ctx.check('LogPath is /var/lib/docker/containers//-json.log', /^\/var\/lib\/docker\/containers\/([0-9a-f]{64})\/\1-json\.log$/m.test(lp.out), lp.out) // ── 2. emergency: rm frees nothing, truncate does ─────────────────────────────────────── run('docker stop chatty', { id: 'stop-chatty' }) const sz = run('sudo du -m "$(docker inspect -f \'{{.LogPath}}\' chatty)"', { id: 'size-before-truncate' }) run('sudo truncate -s 0 "$(docker inspect -f \'{{.LogPath}}\' chatty)"', { id: 'truncate' }) const sz2 = run('sudo du -m "$(docker inspect -f \'{{.LogPath}}\' chatty)"', { id: 'size-after-truncate' }) ctx.check('truncate -s 0 empties the log (tens of MB → 0)', MB(sz.out) >= 10 && MB(sz2.out) === 0, `${sz.out}\n${sz2.out}`) run('docker start chatty', { id: 'start-chatty' }) L('sleep 5') const lg = run('docker logs --tail 1 chatty | wc -c', { id: 'logs-still-work' }) ctx.check('docker logs still works after the truncate (new lines arrive)', Number(lg.out.trim()) > 1000, lg.out) // ── 3. the lasting fix: daemon.json, validated first ──────────────────────────────────── run(`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`, { id: 'daemon-typo' }) const bad = run('sudo dockerd --validate --config-file /etc/docker/daemon.json', { id: 'validate-typo' }) ctx.check('dockerd --validate catches the trailing comma (and Docker keeps running)', bad.exit !== 0 && /unable to configure the Docker daemon with file \/etc\/docker\/daemon\.json/.test(bad.out), bad.out) run(`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`, { id: 'daemon-json' }) const good = run('sudo dockerd --validate --config-file /etc/docker/daemon.json', { id: 'validate' }) ctx.check('dockerd --validate: configuration OK', good.exit === 0 && /configuration OK/.test(good.out), good.out) run('sudo systemctl restart docker', { id: 'restart-docker' }) L('sleep 5') const ps = run("docker ps -a --format '{{.Names}}: {{.Status}}'", { id: 'ps-after-restart' }) ctx.check('after the restart: chatty (unless-stopped) is Up, web (no restart policy) is Exited', /^chatty: Up /m.test(ps.out) && /^web: Exited /m.test(ps.out), ps.out) run('docker start web', { id: 'start-web' }) const lc2 = run("docker inspect -f '{{.HostConfig.LogConfig}}' chatty", { id: 'logconfig-old' }) ctx.check('the existing container still has no limit: {json-file map[]}', /^\{json-file map\[\]\}$/m.test(lc2.out), lc2.out) // ── 4. recreate, and prove the limit holds ────────────────────────────────────────────── run(`docker rm -f chatty\n${CHATTY}`, { id: 'recreate' }) const lc3 = run("docker inspect -f '{{.HostConfig.LogConfig}}' chatty", { id: 'logconfig-new' }) ctx.check('the new container: {json-file map[max-file:3 max-size:10m]}', /^\{json-file map\[max-file:3 max-size:10m\]\}$/m.test(lc3.out), lc3.out) L('sleep 40') // ~100 MB written: more than 3 × 10 MB const ls = run('sudo sh -c \'ls -lh "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log*\'', { id: 'rotated' }) ctx.check('three log files: -json.log, .1 and .2', /-json\.log\.1$/m.test(ls.out) && /-json\.log\.2$/m.test(ls.out) && !/-json\.log\.3$/m.test(ls.out), ls.out) const tot = run('sudo sh -c \'du -cm "$(dirname "$(docker inspect -f "{{.LogPath}}" chatty)")"/*json.log* | tail -n 1\'', { id: 'total' }) ctx.check('all of them together: 31 MB or less after ~100 MB was written', MB(tot.out) > 0 && MB(tot.out) <= 31, tot.out) run('docker rm -f chatty', { id: 'rm-chatty' }) // ── end state ─────────────────────────────────────────────────────────────────────────── const r1 = L("sudo grep -c '\"max-size\"' /etc/docker/daemon.json 2>/dev/null || true") ctx.check('(daemon.json sets a log size limit at the end of the steps)', r1.trim() === '1', r1, { reader: { cmd: "sudo grep -c '\"max-size\"' /etc/docker/daemon.json 2>/dev/null || true", expect: '^1$' }, }) run('docker rm -f web\ndocker run -d --name web --restart unless-stopped nginx:alpine', { id: 'web-recreate' }) const r2 = L("docker ps -q | xargs -r docker inspect -f '{{index .HostConfig.LogConfig.Config \"max-size\"}}' | grep -c 'no value' || true") ctx.check('(every running container has a log size limit at the end of the steps)', r2.trim() === '0', r2, { reader: { cmd: "docker ps -q | xargs -r docker inspect -f '{{index .HostConfig.LogConfig.Config \"max-size\"}}' | grep -c 'no value' || true", expect: '^0$' }, }) ctx.stepsDone() reportBox( ctx, L, `A fresh Ubuntu ${RELEASE} server (${process.env.LIVE_VPS ? 'a rented cloud server, rebuilt to the provider’s stock image' : 'a VM from Ubuntu’s cloud image'}) with Docker Engine installed from Docker’s apt repository, as the install article leaves it, reached over SSH as the sudo user deploy (in the docker group). A test container writes about 2.7 MB of log a second.`, ['docker-ce', 'docker-ce-cli', 'containerd.io'], ) // ── undo ──────────────────────────────────────────────────────────────────────────────── const un = run('docker rm -f web\nsudo rm /etc/docker/daemon.json\nsudo systemctl restart docker', { id: 'undo' }) const st = L('systemctl is-active docker') ctx.check('undo: daemon.json removed and Docker running again', /^active$/m.test(st), `${un.out}\n${st}`) }) export default check