Apply for Free VPS

A Docker container keeps restarting

Updated 27 Nov 2026 docker

Read exit codes and logs to find why a container will not stay up.

Look

docker ps -a
docker logs --tail 100 NAME
docker inspect NAME --format '{{.State.ExitCode}} {{.State.OOMKilled}} {{.State.Error}}'

Read the result

Result Meaning
OOMKilled true, or code 137 Out of memory or killed
Code 127 Command not found
Code 126 Command not executable
Code 1 Application error: read the logs

Common causes

  • A missing environment variable
  • A database not ready yet: add a health check and depends_on with condition: service_healthy
  • A volume owned by the wrong user
  • A port already in use: sudo ss -tlnp
  • A memory limit that is too low

Try it by hand

docker run --rm -it --entrypoint sh IMAGE

Stop the loop while you investigate

docker update --restart=no NAME && docker stop NAME

Was this helpful?

Report outdated or incorrect information