Short answer

A restart loop means the container’s main process keeps exiting and its restart policy starts it again. Stop the loop with docker update --restart=no <name> and docker stop <name>, read why with docker logs <name> and docker inspect (exit code, OOMKilled), fix that cause, then start it again and check that RestartCount stays at 0.

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

The symptom: “Restarting (1) … seconds ago”

The test server ran the official postgres:17 image with --restart always, but without the password it needs. docker ps -a showed:

Server
$ docker ps -aCONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                          PORTS     NAMEScf3e3e05184f   postgres:17   "docker-entrypoint.s…"   50 seconds ago   Restarting (1) 22 seconds ago             db
Output hidden (2 lines)

The number in brackets is the exit code of the last run: 1 means the program inside stopped with an error. Docker then waits and starts it again, so the status flips between a short “Up” and “Restarting”.

Read the exit code, the restart count and the policy

Server
$ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' dbstatus=restarting exit=1 oom=false restarts=10 policy=always
Output hidden (1 line)
  • exit=1: the program failed by itself. 137 would mean it was killed, usually for memory (exit code 137); 0 means it finished normally (exit code 0).
  • oom=false: Docker did not see an out-of-memory kill. With exit code 1 that is right; with 137, check the kernel log (why).
  • restarts=…: how many times Docker started it again. Run the command twice: a number that grows proves the loop.
  • policy=always: the reason it comes back. always and unless-stopped restart after any exit; on-failure only after an error.

Docker waits 100 ms before the first restart and doubles the wait each time, up to one minute. The loop slows down but never ends on its own. Once a container has run for 10 seconds, the wait starts from 100 ms again.

Read the logs: the reason is usually there

docker logs keeps the output of every earlier run, so it works even while the container is down between restarts. The last lines are from the newest crash:

Server
$ docker logs --tail 12 db        See PostgreSQL documentation about "trust":       https://www.postgresql.org/docs/current/auth-trust.htmlError: 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
Output hidden (12 lines)

The cause is plain: the postgres image will not create a database without a superuser password. Every restart hits the same wall, so the loop can never fix itself.

Stop the loop without deleting the container

Turn the restart policy off first, then stop it. The container and its logs stay, so you can keep looking:

Server
$ docker update --restart=no db
Server
$ docker stop db
Server
$ docker ps -aCONTAINER ID   IMAGE         COMMAND                  CREATED              STATUS                      PORTS     NAMEScf3e3e05184f   postgres:17   "docker-entrypoint.s…"   About a minute ago   Exited (1) 22 seconds ago             db
Output hidden (2 lines)

“Exited (1)” and no “Restarting”: the loop has stopped. In the test, RestartCount read the same number five seconds apart.

Fix the cause, then prove it stays up

Here the fix is the missing setting. Settings such as -e cannot be changed on an existing container, so remove it and start a new one with the password. unless-stopped restarts it after a crash or a reboot, but not after you stop it yourself:

Server
$ docker rm db$ export DB_PASS=$(openssl rand -hex 12)$ docker run -d --name db --restart unless-stopped -e POSTGRES_PASSWORD="$DB_PASS" postgres:17dbff8f7ad48fdbcf1ca26e10d0f9269c5f16bf0fddd2d68b4bb9c4ee7d5cc68d7b
Output hidden (2 lines)

Keep $DB_PASS in your password manager: it is the database superuser’s password. Twenty seconds later:

Server
$ docker psCONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS          PORTS      NAMESff8f7ad48fdb   postgres:17   "docker-entrypoint.s…"   28 seconds ago   Up 28 seconds   5432/tcp   db
Output hidden (2 lines)
Server
$ docker inspect -f 'status={{.State.Status}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' dbstatus=running restarts=0 policy=unless-stopped
Output hidden (1 line)
Server
$ docker logs --tail 2 db2026-11-19 08:48:01.353 UTC [62] LOG:  database system was shut down at 2026-11-19 08:48:01 UTC2026-11-19 08:48:01.359 UTC [1] LOG:  database system is ready to accept connections
Output hidden (2 lines)

Up for longer than the earlier runs ever lasted, restarts=0, and the program’s own “ready” line. That is how you know the fix worked, not just that the container started once.

“Restarting (137)”: killed for memory

Exit code 137 means the process was killed (signal 9). The usual killer is the kernel, when the container uses more memory than its limit. To show it, the test started a small container that needs about 60 MB, with a 32 MB limit and --restart always:

Server
$ 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'
Server
$ docker ps -a --filter name=hogCONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                           PORTS     NAMESb1c566be1cc1   alpine    "sh -c 'x=$(head -c …"   21 seconds ago   Restarting (137) 4 seconds ago             hog
Output hidden (2 lines)
Server
$ docker inspect -f 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}} limit={{.HostConfig.Memory}}' hogexit=137 oom=true limit=33554432
Output hidden (1 line)

limit is the limit in bytes (32 MB). Do not trust oom= on its own. Docker sets it only when it catches the kernel’s out-of-memory event before the container’s exit, and it misses some: in our runs on both releases it said oom=false for real out-of-memory kills (the run log lists five more kills and what Docker said for each). The kernel log is the proof:

Server
$ sudo journalctl -k --no-pager | grep -i "memory cgroup out of memory" | tail -n 2Nov 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:0Nov 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
Output hidden (2 lines)

To tie a kill to one container, search the kernel log for its full id. The oom-kill line names the container’s memory group, docker-<id>.scope:

Server
$ sudo journalctl -k --no-pager | grep "$(docker inspect -f '{{.Id}}' hog)" | tail -n 1Nov 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
Output hidden (1 line)

A 137 with no such kernel line means something else sent the kill, such as docker kill. The fix for a real out-of-memory kill is a limit that fits the program, or a program that uses less (for Java or Node.js, a heap size below the container limit). The same command with 256 MB finishes:

Server
$ docker rm -f hog
Server
$ 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
Output hidden (1 line)
Server
$ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}}' hogstatus=exited exit=0 oom=false restarts=0
Output hidden (1 line)
Server
$ docker rm -f hog

“Restarting (0)”: it worked, and still loops

Exit code 0 is success. With always or unless-stopped, Docker restarts it anyway, so a one-off job (a migration, a backup script, echo) loops for ever:

Server
$ docker run -d --name hello --restart always alpine echo hello
Server
$ docker ps -a --filter name=helloCONTAINER ID   IMAGE     COMMAND        CREATED          STATUS                         PORTS     NAMESfb83a6375668   alpine    "echo hello"   17 seconds ago   Restarting (0) 2 seconds ago             hello
Output hidden (2 lines)

Nothing is broken: the policy is wrong for the job. Give one-off jobs --restart no (the default) or on-failure. If it is meant to be a service, its command must stay in the foreground: a start script that launches the program in the background and then exits ends the container.

Server
$ docker rm -f hello

Make Docker give up: on-failure with a count

on-failure:3 restarts after an error at most three times, then leaves the container stopped so you can see its last state:

Server
$ docker run -d --name limited --restart on-failure:3 alpine sh -c 'exit 1'
Server
$ docker inspect -f 'status={{.State.Status}} exit={{.State.ExitCode}} restarts={{.RestartCount}}' limitedstatus=exited exit=1 restarts=3
Output hidden (1 line)
Server
$ docker rm -f limited

In Docker Compose the same setting is restart: on-failure:3. Note what a restart policy does not do: Docker decides on the exit code, a manual stop and the run time only. A container whose healthcheck says “unhealthy” keeps running and is not restarted.

Troubleshooting

  • Restarting (1): the program failed. docker logs --tail 50 <name> shows why: a missing setting, a wrong password, a file it cannot read.
  • Restarting (137): killed. If the kernel log has an oom-kill line with the container’s id, it ran out of memory, even when docker inspect says OOMKilled false. Raise --memory, or make the program use less. Details.
  • Restarting (0): a job that finished, under always. Change the restart policy. Details.
  • It keeps looping while you investigate: docker update --restart=no <name>, then docker stop <name>. 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). Docker’s containers and images live under /var/lib/docker, outside /etc, and no package, service or open port changed: the steps changed only containers.

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. Every command printed the same on both, apart from times and ids. The one thing that changed from run to run, on both releases, is how often Docker missed an out-of-memory kill:

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
Five extra out-of-memory kills (exit 137, all in the kernel log): Docker said OOMKilled false for2 of 54 of 5
ProofRun log, 25 checks passedRun log, 25 checks passed

Undo: remove the test container

Server
$ docker rm -f dbdb
Output hidden (1 line)