ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/docker-container-keeps-restarting Check scripts/live/checks/docker-container-keeps-restarting.mjs (sha256 ffd08f498b874b1421a238fc0b5e032bbef5d4e8a858fb57501bc8cc6c4a5e11) Ran at 2026-11-19T08:45:01Z (449 s) Result PASS, all 25 claims held Tested on System Ubuntu 26.04.1 LTS Kernel 7.0.0-30-generic Package docker-ce 5:29.10.0-1~ubuntu.26.04~resolute Package docker-ce-cli 5:29.10.0-1~ubuntu.26.04~resolute Package containerd.io 2.4.2-4~ubuntu.26.04~resolute Setup A fresh Ubuntu 26.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). The container that loops is the official postgres:17 image started without a password. 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 (0) Files changed in /etc (0) Files removed from /etc (0) Disk used on / (includes logs written during the run): +39.8 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Check-your-server script (2 items): https://cdn.serverhandbook.com/check/docker-container-keeps-restarting/ubuntu-26.04.1-20261119t084501z.sh SHA-256 cef2dd92760189127fbab815c55092ac774bf3adaa155f7e60489d08c43bd4c6 ------------------------------------------------------------------------------ On the stock server, before the first step: FAIL no container is stuck restarting PASS no container has stopped with exit code 137 (killed) After the last step: PASS no container is stuck restarting PASS no container has stopped with exit code 137 (killed) ------------------------------------------------------------------------------ Claims (25), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 26.04 server box (web-server) starts 2. ok (setup) Docker is installed and the docker group exists | docker:x:983: | 29.10.0 3. ok (setup) a new login of deploy is in the docker group | deploy sudo users docker 4. ok docker ps -a: the container shows "Restarting (1) … seconds ago" | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | cf3e3e05184f postgres:17 "docker-entrypoint.s…" 50 seconds ago Restarting (1) 22 seconds ago db 5. ok inspect: exit=1, oom=false, policy=always, restarts counted (3 or more) | status=restarting exit=1 oom=false restarts=10 policy=always 6. ok docker logs: "Database is uninitialized and superuser password is not specified" | See PostgreSQL documentation about "trust": | https://www.postgresql.org/docs/current/auth-trust.html | Error: Database is uninitialized and superuser password is not specified. | You must specify POSTGRES_PASSWORD to a non-empty value for the | superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run". | | You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all | connections without a password. This is *not* recommended. | | See PostgreSQL documentation about "trust": | https://www.postgresql.org/docs/current/auth-trust.html 7. ok after update --restart=no and stop: Exited (1), no longer restarting | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | cf3e3e05184f postgres:17 "docker-entrypoint.s…" About a minute ago Exited (1) 22 seconds ago db 8. ok the restart count no longer grows | 10 then 10 9. ok the fixed container starts (a container id is printed) | db | ff8f7ad48fdbcf1ca26e10d0f9269c5f16bf0fddd2d68b4bb9c4ee7d5cc68d7b 10. ok docker ps: Up for more than 10 seconds, no "Restarting" | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ff8f7ad48fdb postgres:17 "docker-entrypoint.s…" 28 seconds ago Up 28 seconds 5432/tcp db 11. ok inspect: running, restarts=0, policy unless-stopped | status=running restarts=0 policy=unless-stopped 12. ok docker logs: "database system is ready to accept connections" | 2026-11-19 08:48:01.353 UTC [62] LOG: database system was shut down at 2026-11-19 08:48:01 UTC | 2026-11-19 08:48:01.359 UTC [1] LOG: database system is ready to accept connections 13. ok the memory-limited container shows "Restarting (137)" | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | b1c566be1cc1 alpine "sh -c 'x=$(head -c …" 21 seconds ago Restarting (137) 4 seconds ago hog 14. ok inspect: exit=137 and the 32 MB limit (33554432 bytes); oom= is recorded as Docker reports it | exit=137 oom=true limit=33554432 15. ok the kernel log says "Memory cgroup out of memory: Killed process" | Nov 19 08:49:13 web-server kernel: Memory cgroup out of memory: Killed process 7102 (sh) total-vm:38520kB, anon-rss:31952kB, file-rss:884kB, shmem-rss:0kB, UID:0 pgtables:112kB oom_score_adj:0 | Nov 19 08:49:13 web-server kernel: Memory cgroup out of memory: Killed process 7128 (head) total-vm:1640kB, anon-rss:60kB, file-rss:872kB, shmem-rss:0kB, UID:0 pgtables:44kB oom_score_adj:0 16. ok the kernel's oom-kill line names this container's cgroup (docker-.scope) | Nov 19 08:49:13 web-server kernel: oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,mems_allowed=0,oom_memcg=/system.slice/docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,task_memcg=/system.slice/docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,task=head,pid=7128,uid=0 17. ok (five more out-of-memory kills: all exit 137 and in the kernel log; OOMKilled as Docker reported it) | oom1: exit=137 oom=true | kernel: killed in docker-7eaaba0c8e88…scope | oom2: exit=137 oom=true | kernel: killed in docker-7c02ccdde275…scope | oom3: exit=137 oom=false | kernel: killed in docker-9f6fae213945…scope | oom4: exit=137 oom=true | kernel: killed in docker-60365b93153a…scope | oom5: exit=137 oom=false | kernel: killed in docker-15997f344a25…scope 18. ok with a 256 MB limit the same command finishes: "done" | done 19. ok inspect: exited 0, oom=false, restarts=0 | status=exited exit=0 oom=false restarts=0 20. ok a container that ends cleanly under "always" shows "Restarting (0)" | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | fb83a6375668 alpine "echo hello" 17 seconds ago Restarting (0) 2 seconds ago hello 21. ok on-failure:3 gave up: exited, exit=1, restarts=3 | status=exited exit=1 restarts=3 22. ok (no container is stuck restarting at the end of the steps) | 0 23. ok (no container has stopped with exit code 137 at the end of the steps) | 0 24. ok (tested on) the box reports its OS, kernel and the version of 3 package(s) | PRETTY_NAME="Ubuntu 26.04.1 LTS" | VIRT=none | KERNEL=7.0.0-30-generic | PKG containerd.io 2.4.2-4~ubuntu.26.04~resolute | PKG docker-ce 5:29.10.0-1~ubuntu.26.04~resolute | PKG docker-ce-cli 5:29.10.0-1~ubuntu.26.04~resolute 25. ok undo: docker rm -f removes the container | db ------------------------------------------------------------------------------ Commands and what they printed (26) ------------------------------------------------------------------------------ $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cf3e3e05184f postgres:17 "docker-entrypoint.s…" 50 seconds ago Restarting (1) 22 seconds ago db $ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' db status=restarting exit=1 oom=false restarts=10 policy=always $ docker logs --tail 12 db See PostgreSQL documentation about "trust": https://www.postgresql.org/docs/current/auth-trust.html Error: Database is uninitialized and superuser password is not specified. You must specify POSTGRES_PASSWORD to a non-empty value for the superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run". You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all connections without a password. This is *not* recommended. See PostgreSQL documentation about "trust": https://www.postgresql.org/docs/current/auth-trust.html $ docker update --restart=no db db $ docker stop db db $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cf3e3e05184f postgres:17 "docker-entrypoint.s…" About a minute ago Exited (1) 22 seconds ago db $ docker rm db $ export DB_PASS=$(openssl rand -hex 12) $ docker run -d --name db --restart unless-stopped -e POSTGRES_PASSWORD="$DB_PASS" postgres:17 db ff8f7ad48fdbcf1ca26e10d0f9269c5f16bf0fddd2d68b4bb9c4ee7d5cc68d7b $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ff8f7ad48fdb postgres:17 "docker-entrypoint.s…" 28 seconds ago Up 28 seconds 5432/tcp db $ docker inspect -f 'status={{.State.Status}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' db status=running restarts=0 policy=unless-stopped $ docker logs --tail 2 db 2026-11-19 08:48:01.353 UTC [62] LOG: database system was shut down at 2026-11-19 08:48:01 UTC 2026-11-19 08:48:01.359 UTC [1] LOG: database system is ready to accept connections $ docker run -d --name hog --restart always --memory 32m --memory-swap 32m alpine sh -c 'x=$(head -c 60000000 /dev/zero | tr "\0" a); echo done' b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a $ docker ps -a --filter name=hog CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b1c566be1cc1 alpine "sh -c 'x=$(head -c …" 21 seconds ago Restarting (137) 4 seconds ago hog $ docker inspect -f 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}} limit={{.HostConfig.Memory}}' hog exit=137 oom=true limit=33554432 $ sudo journalctl -k --no-pager | grep -i "memory cgroup out of memory" | tail -n 2 Nov 19 08:49:13 web-server kernel: Memory cgroup out of memory: Killed process 7102 (sh) total-vm:38520kB, anon-rss:31952kB, file-rss:884kB, shmem-rss:0kB, UID:0 pgtables:112kB oom_score_adj:0 Nov 19 08:49:13 web-server kernel: Memory cgroup out of memory: Killed process 7128 (head) total-vm:1640kB, anon-rss:60kB, file-rss:872kB, shmem-rss:0kB, UID:0 pgtables:44kB oom_score_adj:0 $ sudo journalctl -k --no-pager | grep "$(docker inspect -f '{{.Id}}' hog)" | tail -n 1 Nov 19 08:49:13 web-server kernel: oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,mems_allowed=0,oom_memcg=/system.slice/docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,task_memcg=/system.slice/docker-b1c566be1cc15a851409e087b28137c410afe4af0707b4ab5a65e1211a07124a.scope,task=head,pid=7128,uid=0 $ docker rm -f hog hog $ docker run --name hog --restart on-failure:3 --memory 256m --memory-swap 256m alpine sh -c 'x=$(head -c 60000000 /dev/zero | tr "\0" a); echo done' done $ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}}' hog status=exited exit=0 oom=false restarts=0 $ docker rm -f hog hog $ docker run -d --name hello --restart always alpine echo hello fb83a6375668a6027be5ce563ea9d48259554200ae8b35ad75b7192adec6b059 $ docker ps -a --filter name=hello CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fb83a6375668 alpine "echo hello" 17 seconds ago Restarting (0) 2 seconds ago hello $ docker rm -f hello hello $ docker run -d --name limited --restart on-failure:3 alpine sh -c 'exit 1' 806e85f4d44423a184f69b0cf92cb816421bedc2c67f36c3dc08ad6cdd27c6c2 $ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} restarts={{.RestartCount}}' limited status=exited exit=1 restarts=3 $ docker rm -f limited limited $ docker rm -f db db ------------------------------------------------------------------------------ The check-your-server script, its full screen before the steps ------------------------------------------------------------------------------ ServerHandbook check, docker-container-keeps-restarting (proved 2026-11-19) FAIL no container is stuck restarting fix: https://serverhandbook.com/kb/docker-container-keeps-restarting#stop-the-loop PASS no container has stopped with exit code 137 (killed) 1 passed, 1 failed To fix a FAIL, follow the steps in https://serverhandbook.com/kb/docker-container-keeps-restarting ------------------------------------------------------------------------------ The check-your-server script, its full screen after the steps ------------------------------------------------------------------------------ ServerHandbook check, docker-container-keeps-restarting (proved 2026-11-19) PASS no container is stuck restarting PASS no container has stopped with exit code 137 (killed) 2 passed, 0 failed ------------------------------------------------------------------------------ The check's source (scripts/live/checks/docker-container-keeps-restarting.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB fix: "Docker container keeps restarting" (`docker ps` shows "Restarting (1) 8 seconds ago"). The real loop is a * postgres container started without POSTGRES_PASSWORD (it exits 1 every start; restart policy "always" starts it * again). Steps: see the loop; read policy, exit code and RestartCount; read the logs; stop the loop * (docker update --restart=no, docker stop); fix the cause and prove it stays up (RestartCount 0). Then the other * loops by exit code: 137 + OOMKilled (a 32 MB limit), exit 0 under `restart: always`, and `on-failure:3` giving up. * * Runs on a fresh server (the local VM box). Docker Engine is installed first exactly as the install article does it * (hidden), and the broken container is the stock state the reader starts from (hidden). */ import { bareBox, reportBox } from '../lib.mjs' export const meta = { // The reader's check-your-server script (plan05 phase 3): proved on the stock server and after the steps. reader: [ { item: 'no container is stuck restarting', cmd: "docker ps -a --filter status=restarting -q | wc -l", expect: '^0$', step: 'stop-the-loop', }, { // Not OOMKilled: Docker misses the kernel's OOM event for some kills (exit 137, OOMKilled false; 2026-11-19, // both releases). The exit code is always there. item: 'no container has stopped with exit code 137 (killed)', cmd: 'docker ps -a --filter exited=137 -q | wc -l', expect: '^0$', step: 'exit-137', }, ], } const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const CODENAME = { '24.04': 'noble', '26.04': 'resolute' }[RELEASE] const INSTALL = [ // This laptop's network has no working IPv6 and apt hung 22 minutes on archive.ubuntu.com over it (2026-11-19). // Transport only, set before the first step (outside the footprint): what apt installs is unchanged. `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(' && ') const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() // ── hidden: Docker Engine as the install article leaves it, the docker group, and the broken container ── L(INSTALL, 1800000) // The setup must hold before the first step (2026-11-19: a slow install left usermod before the docker group // existed, and every step then said "permission denied" on docker.sock). const grp = L('getent group docker && sudo docker version -f "{{.Server.Version}}"') 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 postgres:17', 600000) L('sudo docker pull -q alpine', 600000) L('sudo docker run -d --name db --restart always postgres:17 >/dev/null') L('sleep 14') // the loop is running and has backed off a few times // ── 1. the symptom ────────────────────────────────────────────────────────────────────── const ps = run('docker ps -a', { id: 'ps-loop' }) ctx.check('docker ps -a: the container shows "Restarting (1) … seconds ago"', /\bRestarting \(1\) .* ago/.test(ps.out) && /\bdb\s*$/m.test(ps.out), ps.out) // ── 2. what Docker knows: policy, exit code, count ────────────────────────────────────── const ins = run("docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' db", { id: 'inspect-loop' }) ctx.check('inspect: exit=1, oom=false, policy=always, restarts counted (3 or more)', /exit=1 oom=false restarts=([3-9]|\d\d+) policy=always/.test(ins.out), ins.out) // ── 3. the logs say why ───────────────────────────────────────────────────────────────── const lg = run('docker logs --tail 12 db', { id: 'logs' }) ctx.check('docker logs: "Database is uninitialized and superuser password is not specified"', /Database is uninitialized and superuser password is not specified/.test(lg.out), lg.out) // ── 4. stop the loop ──────────────────────────────────────────────────────────────────── run('docker update --restart=no db', { id: 'update-no' }) run('docker stop db', { id: 'stop' }) const ps2 = run('docker ps -a', { id: 'ps-stopped' }) ctx.check('after update --restart=no and stop: Exited (1), no longer restarting', /\bExited \(1\) /.test(ps2.out) && !/Restarting/.test(ps2.out), ps2.out) const c1 = L("docker inspect -f '{{.RestartCount}}' db") L('sleep 5') const c2 = L("docker inspect -f '{{.RestartCount}}' db") ctx.check('the restart count no longer grows', c1.trim() === c2.trim(), `${c1.trim()} then ${c2.trim()}`) // ── 5. fix the cause and prove it stays up ────────────────────────────────────────────── const fix = run( 'docker rm db\nexport DB_PASS=$(openssl rand -hex 12)\ndocker run -d --name db --restart unless-stopped -e POSTGRES_PASSWORD="[password]" postgres:17', { id: 'fix', timeout: 300000 }, ) ctx.check('the fixed container starts (a container id is printed)', /^[0-9a-f]{64}$/m.test(fix.out), fix.out) L('sleep 20') const up = run('docker ps', { id: 'ps-fixed' }) ctx.check('docker ps: Up for more than 10 seconds, no "Restarting"', /\bUp (\d+ seconds|About a minute|\d+ minutes?)\b/.test(up.out) && /\bdb\s*$/m.test(up.out), up.out) const ok = run("docker inspect -f 'status={{.State.Status}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' db", { id: 'inspect-fixed' }) ctx.check('inspect: running, restarts=0, policy unless-stopped', /status=running restarts=0 policy=unless-stopped/.test(ok.out), ok.out) const rl = run('docker logs --tail 2 db', { id: 'logs-fixed' }) ctx.check('docker logs: "database system is ready to accept connections"', /database system is ready to accept connections/.test(rl.out), rl.out) // ── 6. exit 137: out of memory ────────────────────────────────────────────────────────── const hog = "docker run -d --name hog --restart always --memory 32m --memory-swap 32m alpine sh -c 'x=$(head -c 60000000 /dev/zero | tr \"\\0\" a); echo done'" run(hog, { id: 'hog-start' }) L('sleep 12') const hps = run('docker ps -a --filter name=hog', { id: 'hog-ps' }) ctx.check('the memory-limited container shows "Restarting (137)"', /\bRestarting \(137\) /.test(hps.out), hps.out) const hin = run("docker inspect -f 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}} limit={{.HostConfig.Memory}}' hog", { id: 'hog-inspect' }) // oom= is true OR false: Docker sets it only when it receives the kernel's OOM event, and it misses some. ctx.check('inspect: exit=137 and the 32 MB limit (33554432 bytes); oom= is recorded as Docker reports it', /exit=137 oom=(true|false) limit=33554432/.test(hin.out), hin.out) const kl = run('sudo journalctl -k --no-pager | grep -i "memory cgroup out of memory" | tail -n 2', { id: 'hog-kernel' }) ctx.check('the kernel log says "Memory cgroup out of memory: Killed process"', /Memory cgroup out of memory: Killed process \d+ \(/.test(kl.out), kl.out) const kid = run(`sudo journalctl -k --no-pager | grep "$(docker inspect -f '{{.Id}}' hog)" | tail -n 1`, { id: 'hog-kernel-id' }) ctx.check("the kernel's oom-kill line names this container's cgroup (docker-.scope)", /oom-kill:constraint=CONSTRAINT_MEMCG,.*cpuset=docker-[0-9a-f]{64}\.scope/.test(kid.out), kid.out) run('docker rm -f hog', { id: 'hog-rm' }) // Evidence for the page's warning, recorded in every run log: five more kills, and what Docker said for each. const sample = [] for (let i = 1; i <= 5; i++) { L(`docker run --name oom${i} --memory 32m --memory-swap 32m alpine sh -c 'exec tail /dev/zero' >/dev/null 2>&1; true`, 120000) sample.push(L(`docker inspect -f 'oom${i}: exit={{.State.ExitCode}} oom={{.State.OOMKilled}}' oom${i}; [ "$(sudo journalctl -k --no-pager | grep -c "$(docker inspect -f '{{.Id}}' oom${i})")" -gt 0 ] && echo " kernel: killed in docker-$(docker inspect -f '{{.Id}}' oom${i} | cut -c1-12)…scope"`).trim()) L(`docker rm -f oom${i} >/dev/null`) } ctx.check('(five more out-of-memory kills: all exit 137 and in the kernel log; OOMKilled as Docker reported it)', sample.every((x) => /exit=137/.test(x) && /kernel: killed/.test(x)), sample.join('\n')) const hog2 = run( "docker run --name hog --restart on-failure:3 --memory 256m --memory-swap 256m alpine sh -c 'x=$(head -c 60000000 /dev/zero | tr \"\\0\" a); echo done'", { id: 'hog-fixed' }, ) ctx.check('with a 256 MB limit the same command finishes: "done"', /^done$/m.test(hog2.out), hog2.out) const hin2 = run("docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}}' hog", { id: 'hog-inspect-fixed' }) ctx.check('inspect: exited 0, oom=false, restarts=0', /status=exited exit=0 oom=false restarts=0/.test(hin2.out), hin2.out) run('docker rm -f hog', { id: 'hog-rm2' }) // ── 7. exit 0 under "always" ──────────────────────────────────────────────────────────── run('docker run -d --name hello --restart always alpine echo hello', { id: 'hello-start' }) L('sleep 8') const hs = run('docker ps -a --filter name=hello', { id: 'hello-ps' }) ctx.check('a container that ends cleanly under "always" shows "Restarting (0)"', /\bRestarting \(0\) /.test(hs.out), hs.out) run('docker rm -f hello', { id: 'hello-rm' }) // ── 8. on-failure:3 gives up ──────────────────────────────────────────────────────────── run("docker run -d --name limited --restart on-failure:3 alpine sh -c 'exit 1'", { id: 'limited-start' }) L('sleep 8') const lim = run("docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} restarts={{.RestartCount}}' limited", { id: 'limited-inspect' }) ctx.check('on-failure:3 gave up: exited, exit=1, restarts=3', /status=exited exit=1 restarts=3/.test(lim.out), lim.out) run('docker rm -f limited', { id: 'limited-rm' }) // ── end state (reader checks) ─────────────────────────────────────────────────────────── const rs = L("docker ps -a --filter status=restarting -q | wc -l") ctx.check('(no container is stuck restarting at the end of the steps)', rs.trim() === '0', rs, { reader: { cmd: 'docker ps -a --filter status=restarting -q | wc -l', expect: '^0$' }, }) const k137 = L('docker ps -a --filter exited=137 -q | wc -l') ctx.check('(no container has stopped with exit code 137 at the end of the steps)', k137.trim() === '0', k137, { reader: { cmd: 'docker ps -a --filter exited=137 -q | wc -l', expect: '^0$' }, }) ctx.stepsDone() // the article's steps end here; the undo follows 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). The container that loops is the official postgres:17 image started without a password.`, ['docker-ce', 'docker-ce-cli', 'containerd.io'], ) // ── undo ──────────────────────────────────────────────────────────────────────────────── const rm = run('docker rm -f db', { id: 'undo' }) ctx.check('undo: docker rm -f removes the container', /^db$/m.test(rm.out), rm.out) }) export default check