Reported symptoms
- Container keeps restarting.
docker psshows highRestartCount.docker inspectshows the container has a non-zero exit code.
Evidence provided
$ docker ps -a
CONTAINER ID STATUS NAMES
abc123def456 Restarting (1) 5 seconds ago api
$ docker inspect abc123def456 --format '{{.State.ExitCode}}'
137
$ docker logs abc123def456 --tail 30
... application output, then a final line, then exit ...
... the application process exits with 137 (SIGKILL) or another non-zero code ...
The exit code 137 here is illustrative - your scenario’s exit code is whatever the application produced. The procedure below works from any non-zero exit.
Resolution path
- Distinguish exit from unhealthy.
docker inspect <id> --format "{{.State.Status}}"reports one ofrunning,restarting,exited,paused,dead. A container inrestartingis exiting fast enough that the daemon has not yet reported it asexited. Look at{{.State.ExitCode}}.- Read the application logs from the last cycle.
docker logs <id> --tail 50. The application exit reason is in here, not in the health check.- Run the entrypoint manually.
docker run --rm -it <image> <entrypoint>reproduces the failure without the restart loop in the way. Same image, same entrypoint, no--restart.- Fix the application or its configuration.
- Common causes: missing config file (volume not mounted), database unreachable, panic on startup, OOM kill (check
dmesgand the host cgroup). - Cap restart attempts if you need time to investigate.
docker run --restart on-failure:5 <image> <entrypoint>retries at most five times. Five failed restarts in a row is the daemon telling you the application is broken; fix the application, do not raise the cap.
Verification
- Exit code returns to 0.
docker inspect <id> --format "{{.State.ExitCode}}"returns0.- Container stays Up.
docker psshowsUp X minutes.- The restart count stops climbing.
docker inspect <id> --format "{{.RestartCount}}"is stable.