ismysiteup
FeaturesPricingToolsIs it down?BlogSign InGet Started
ismysiteup

All-in-one website monitoring: uptime, widgets, servers and APIs, with alerts on WhatsApp, Telegram, Slack and email. Know before your client does.

contact@ismysiteup.netInstagram

Product

  • Uptime monitoring
  • Apps & Widgets
  • Server monitoring
  • API tools & Data Monitors
  • Pricing

Resources

  • Free tools
  • Is it down?
  • Blog
  • HTTP status codes
  • API docs
  • Alert channels
  • Compare

Legal

  • Terms of Service
  • Privacy Policy

© 2026 Sea Jay Media Digital Marketing LLC. All rights reserved.

The service is provided as is. See the Terms.

HomeBlogHow-To GuidesDocker Container Keeps Restarting? How to Find the Cause and Get Alerted
How-To Guides

Docker Container Keeps Restarting? How to Find the Cause and Get Alerted

November 25, 2026
10 min read

Written by ismysiteup

If your Docker container keeps restarting, Docker isn't the problem. The main process inside the container (PID 1) is exiting, and a restart policy such as always or unless-stopped starts it again, over and over. docker ps shows Restarting (1) 3 seconds ago, your app is half-working or down, and nothing tells you. This guide shows how to find the cause in a few commands, stop the loop safely while you fix it, and get an alert the next time a container stops or gets stuck in a restart loop.

Why a Docker container keeps restarting: the short answer

A container lives exactly as long as its main process. When that process exits, the restart policy decides what happens next. With always, unless-stopped or on-failure, an app that fails at startup is started again, fails again, and you get a restart loop. Docker waits a little longer before each attempt, so the loop can look like flakiness rather than a crash.

The most common causes:

  • A startup error: a missing variable, bad config or failed migration (usually exit code 1).
  • A dependency that isn't ready: the database or API isn't reachable yet.
  • Out of memory: the kernel kills the process (exit code 137).
  • A wrong command or entrypoint: exit codes 126 and 127.
  • Nothing in the foreground: the server goes to the background and PID 1 finishes (exit code 0).
  • A crash in native code: a segmentation fault (exit code 139).

Step 1: Find the containers that are stopped or restarting

Start with the full list, including stopped containers:

docker ps -a

To show only the problem ones, filter by status:

docker ps -a --filter status=restarting
docker ps -a --filter status=exited

With Compose, use docker compose ps -a. The number in brackets after Restarting or Exited is the last exit code: your first clue.

Step 2: Read the logs from the failed runs

Logs from earlier attempts are kept while the container exists:

docker logs --tail 100 --timestamps <container>

For a Compose service, use the service name:

docker compose logs --tail 100 <service>

Look for the first real error before the startup messages repeat: "permission denied", "address already in use", "connection refused" or a missing variable. Read the logs before changing anything: docker compose down removes the old container and its logs.

Docker container keeps restarting with no logs

If docker logs is empty, the process probably died before printing anything (a wrong entrypoint, an image built for another CPU, a SIGKILL), or the app logs to a file instead of stdout. Then docker inspect and docker events tell you more than the logs.

Step 3: Check the exit code, OOMKilled flag and restart count

docker inspect shows how the last run ended and how many times Docker has restarted the container:

docker inspect --format 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} restarts={{.RestartCount}} policy={{.HostConfig.RestartPolicy.Name}}' <container>

You might see status=restarting exit=1 oom=false restarts=14 policy=always. Once the container runs again, ExitCode goes back to 0, so watch the event stream to catch each crash:

docker events --filter container=<container> --filter event=die

Each die event carries the exit code. An oom event just before a die points to a memory kill.

Docker container exit codes explained

Exit code What it means Where to look
0 The process finished normally The command ends right away, or the app moves itself to the background
1 (or another small number) The app hit an error and quit Application logs, config, env variables, dependencies
125 Docker itself couldn't run the container The docker run flags or Compose file (port or name conflicts, bad options)
126 The command was found but can't be executed File permissions, missing execute bit, wrong interpreter
127 The command wasn't found ENTRYPOINT/CMD, paths, whether the binary is in the image
137 Killed with SIGKILL (128 + 9) OOMKilled, memory limits, docker kill, a stop that timed out
139 Segmentation fault (128 + 11) Native libraries, image architecture, app bugs
143 Stopped with SIGTERM (128 + 15) A normal docker stop, a redeploy, or something on the host stopping it

Step 4: Fix the most common causes

Docker container exited with code 137 (out of memory)

Exit code 137 means SIGKILL. It's often an out-of-memory kill, but docker kill, or a docker stop where the app ignores SIGTERM for the grace period (10 seconds by default), also ends in 137. Confirm first:

docker inspect --format '{{.State.OOMKilled}}' <container>
docker stats --no-stream
sudo dmesg -T | grep -i -E 'out of memory|killed process'

If it is memory, raise the limit (--memory, or the limit in your Compose file), reduce what the app uses, or add RAM.

Exit code 1: configuration and dependencies

Most code 1 loops are a missing environment variable, an unmounted config file, or a database that isn't ready yet. In Compose, let the app wait for a healthy database:

services:
  db:
    image: postgres:16
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
  app:
    build: .
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy

Docker container exits immediately with code 0

A repeating clean exit means the main command finishes: a start script runs the server with & and ends, or a server like nginx moves itself to the background. Run it in the foreground (for example CMD ["nginx", "-g", "daemon off;"]) and end entrypoint scripts with exec "$@".

Codes 126 and 127: the entrypoint can't run

Check the execute bit (chmod +x), that the script's shell exists in the image (Alpine has sh, not bash), and that it has no Windows line endings.

Step 5: Stop the restart loop safely while you debug

You can't docker exec into a restarting container. Turn the policy off without deleting anything:

docker update --restart=no <container>

It stops at its next exit and stays Exited, logs intact. Then open a throwaway copy of the image with a shell and run the start command by hand:

docker run --rm -it --entrypoint sh <image>

With Compose: docker compose run --rm --no-deps --entrypoint sh <service>. Once fixed, restore the policy with docker update --restart=unless-stopped <container> or redeploy.

Docker restart policies: always vs unless-stopped vs on-failure

Policy What Docker does
no (default) Never restarts the container
on-failure[:max-retries] Restarts only after a non-zero exit, optionally a limited number of times
always Restarts after any exit; a container you stop by hand comes back when the Docker daemon restarts
unless-stopped Like always, but a container you stopped stays stopped, even after a daemon restart

For most web apps unless-stopped is a sensible default; on-failure:5 caps the retries instead of looping forever. Either way, a restart policy hides crashes: it keeps the service coming back without telling anyone.

Healthchecks: when a container is "running" but unhealthy

A HEALTHCHECK runs a command inside the container on a schedule and marks it healthy or unhealthy. Defaults: every 30 seconds, 30-second timeout, unhealthy after 3 failures in a row. A start period gives slow apps time to boot.

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
  CMD curl -fsS http://localhost:8080/health || exit 1

Two surprises: the Docker Engine doesn't restart a standalone container just because it's unhealthy (restart policies react to the process exiting; Swarm services differ), and a check that calls curl in an image without curl fails forever. See the result with docker inspect --format '{{json .State.Health}}' <container>.

How to monitor Docker containers so a restart loop doesn't go unnoticed

The hard part isn't fixing restart loops, it's noticing them. The site may still answer from a cache, a worker may silently stop processing jobs, and the restart policy keeps everything looking busy. Ways to watch for it:

  • Check by hand: docker ps -a works, when you remember to look.
  • Self-hosted stacks: Prometheus with cAdvisor and Grafana, Netdata or Uptime Kuma, which you set up and maintain yourself.
  • An uptime check on the app's URL: catches a dead site, but not which container broke, and misses workers with no URL.
  • A container-level alert: tells you when a container stops, loops or disappears.

ismysiteup's server monitoring does the last one. A small agent on your Linux server reads the container list when Docker is installed (optional: install with --no-docker to leave it out) and shows each container's state, restart count, CPU and memory. Tick "Alert me" on the containers that matter, and you get one message when a container stops, keeps restarting or disappears, and one when it's running again. Ten containers failing together arrive as one message. Containers recreated on every deploy (Docker Swarm, Dokploy) are recognised by service name, so a redeploy isn't a disappearance. Alerts cover 5 containers per server on the Free plan and 15 on Pro and Business. It works with Compose and Swarm, not Kubernetes pods.

The agent is read-only: it opens no port, accepts no commands and can't start, stop or restart a container. Your restart policy restarts; the alert tells you when that isn't working. Read how the read-only monitoring agent works first. It also alerts on high CPU or memory and disks filling up, common reasons a container gets killed. See the Linux server monitoring features or our guide to free Linux server monitoring.

Pair it with an uptime monitor for the site itself (checks as often as every 10 minutes on Free, 5 on Pro and 1 on Business) so you know both that the site is down and which container caused it. Alerts go to the chat apps you already use: WhatsApp, Telegram, Slack or email. You can create a free account with no credit card.

FAQ

Why does my Docker container keep restarting?

Its main process keeps exiting and a restart policy starts it again. Use docker logs and docker inspect to find the error and exit code, then fix the cause: usually config, a dependency, memory or the start command.

What does exit code 137 mean in Docker?

The process was killed with SIGKILL (128 + 9). It's often an out-of-memory kill, so check OOMKilled in docker inspect and the kernel log. A docker kill or a stop that timed out also gives 137.

Why does my Docker container exit immediately?

The main command finished, either with a startup error (non-zero code) or cleanly (code 0) because the server went to the background. Run the app in the foreground as PID 1.

How do I stop a Docker container from restarting?

Run docker update --restart=no <container>. It stops at its next exit and stays stopped, with its logs. With always, a plain docker stop can come back when the Docker daemon restarts.

Does Docker restart an unhealthy container?

Not on its own. Restart policies only react to the main process exiting. Unhealthy shows in docker ps and docker inspect, but nothing restarts it unless something like Swarm acts on it.

How do I get an alert when a Docker container stops?

Use a monitor that reads container state on the server. ismysiteup's read-only agent sends one message when a chosen container stops, keeps restarting or disappears, and one when it's back.

Sources

  • Start containers automatically – Docker Docs
  • Running containers – Docker Docs
  • Dockerfile reference – Docker Docs
  • docker system events – Docker Docs
  • Resource constraints – Docker Docs
  • Docker exit code 137 (OOMKilled): out of memory or not? – OpsMate (itops.sh)

On this page

  • Why a Docker container keeps restarting: the short answer
  • Step 1: Find the containers that are stopped or restarting
  • Step 2: Read the logs from the failed runs
  • Docker container keeps restarting with no logs
  • Step 3: Check the exit code, OOMKilled flag and restart count
  • Docker container exit codes explained
  • Step 4: Fix the most common causes
  • Docker container exited with code 137 (out of memory)
  • Exit code 1: configuration and dependencies
  • Docker container exits immediately with code 0
  • Codes 126 and 127: the entrypoint can't run
  • Step 5: Stop the restart loop safely while you debug
  • Docker restart policies: always vs unless-stopped vs on-failure
  • Healthchecks: when a container is "running" but unhealthy
  • How to monitor Docker containers so a restart loop doesn't go unnoticed
  • FAQ
  • Why does my Docker container keep restarting?
  • What does exit code 137 mean in Docker?
  • Why does my Docker container exit immediately?
  • How do I stop a Docker container from restarting?
  • Does Docker restart an unhealthy container?
  • How do I get an alert when a Docker container stops?
  • Sources

Tags

alerts
debugging
downtime
uptime monitoring
web development

Share this article

TweetLinkedIn

Related Posts

How-To Guides

WordPress Site Down? A Recovery Checklist for Small Businesses

WordPress site down? This 10-step recovery checklist helps small businesses fix database connection errors, the white screen of death and critical errors, then set up alerts so you hear about the next outage first.

November 2, 2026·11 min read
How-To Guides

Free Linux Server Monitoring: A Lightweight, Read-Only Setup

Free Linux server monitoring without running a Grafana stack: what to watch on a VPS, how the free tools compare, and how to set up a lightweight, read-only agent with alerts in a minute.

November 16, 2026·11 min read
How-To Guides

Third-Party Script Monitoring: Catch Broken Site Widgets

Your site is up but the chat widget is gone? Learn what third-party script monitoring is, why widgets stop loading, and how to check and monitor them for free.

November 16, 2026·10 min read
How-To Guides

Why Is My Website Down? 10 Causes and a Fix-It Checklist

Site won't load and it's not just you? Here's why your website is down, plus a 10-step troubleshooting checklist to find the cause and get it back online fast.

October 30, 2026·10 min read

Monitor your websites for free

Get instant email, Telegram, and WhatsApp alerts when your sites go down. Free plan checks every 10 minutes. No credit card required.

Start Monitoring Free