Fix Docker Container Restarting — Stop Restart Loops

Direct answer

Docker containers restart when the main process exits with a non-zero code and the restart policy triggers a retry. Exit code 137 indicates OOM kill, exit code 1 indicates an application error. Check docker logs and docker inspect to identify the failure.

Structured breakdown

Cause

Docker containers restart due to OOM kills, application errors, or misconfigured health checks. Check docker logs and inspect the exit code to identify the exact failure.

Fix

  • Run docker logs <container-id> to see the last error output
  • Check the exit code with docker inspect <container-id> --format='{{.State.ExitCode}}'
  • Increase memory limits in docker run --memory or docker-compose.yml

Outcome

Container runs without restart loops and the root cause exit code is resolved.

Common causes

  • Out of memory (exit code 137 — OOMKilled)
  • Application crash with unhandled exception (exit code 1)
  • Misconfigured HEALTHCHECK causing restart
  • Missing environment variables or config files
  • Entrypoint script failing silently

Fix steps

  1. 1

    Run docker logs <container-id> to see the last error output

  2. 2

    Check the exit code with docker inspect <container-id> --format='{{.State.ExitCode}}'

  3. 3

    Increase memory limits in docker run --memory or docker-compose.yml

  4. 4

    Validate all environment variables and mounted volumes are correct

  5. 5

    Test the entrypoint script locally to catch silent failures

Analyze this issue

Paste the issue description, logs, or symptoms into the fix tool to inspect this problem with your own runtime details.

kintify fix

Need more context?

If the standard steps do not resolve the issue, open the fix tool and include the current logs, configuration, and deployment changes.

Open Fix Tool

Frequently asked questions

These examples show the commands, logs, and configuration patterns most often used to verify this issue.

Command examples

  • docker logs <container-id> --tail 50
  • docker inspect <container-id> --format='{{.State.ExitCode}}'
  • docker stats --no-stream

Log snippet

container exited with status 137
OOMKilled: true
Memory limit: 256MiB
Peak usage: 312MiB

Config snippet

services:
  app:
    deploy:
      resources:
        limits:
          memory: 512M
    restart: unless-stopped