Skip to content

Troubleshoot Docker Containers That Exit or Keep Restarting

Admin
November 18, 2026
5 min read
Intermediate
💻 Target OS: Ubuntu 24.04+ / Debian 12+ / RHEL 9+

Before you begin

  • Applies to:Docker Engine on Linux with Compose v2. The steps assume one replica per service.
  • Where to start:Open a terminal in the deployed project directory. Use the same Docker context, project name, and Compose files as the deployment.
  • What you need:Use an account authorized to run Docker commands. Have the affected service name ready and replace the example name app. Keep the same shell for commands that share variables.
Guide tools
Guide tools
0/0 Steps (0%)

A restart policy can keep a failed process coming back. Capture the last exit state and logs before recreating the container. A one-shot job exiting successfully may have completed normally.

Troubleshooting Steps

01

Identify which service is failing

Inventory

The —all option includes stopped containers. Record the service and container ID, then read the latest 80 log lines with timestamps. If logs are empty, inspect the engine error field and check whether the app logs to files or a different sink.

Terminal window
docker compose ps --all
docker compose logs --tail 80 --timestamps app
02

Distinguish an application exit from a runtime failure

State

Copy the affected container ID from the first step into the variable. Check OOMKilled and the memory limit. Exit code 137 indicates SIGKILL in typical cases and can also follow a forced stop. OOMKilled is stronger evidence. A nonempty Error field can identify a runtime startup failure before the app writes logs.

What you should see · The container state and logs tell you whether Docker could start the container and whether the app then exited.

If you see something else · Start with the runtime error if the Error field is populated. If Docker reports OOMKilled, compare the configured limit and measured demand. If the app logged an error, take that error into Step 3 before recreating the container.

Terminal window
container='example-app-1'
docker inspect --type container --format '{{json .State}}' "$container"
docker inspect --type container --format 'restarts={{.RestartCount}} restart={{.HostConfig.RestartPolicy.Name}} memory_bytes={{.HostConfig.Memory}}' "$container"
03

Correct the confirmed cause

Diagnosis

For a file or permission error compare the container mount with the intended host path and runtime user. For a missing setting restore it through the configured secret or environment source. For a confirmed OOM review observed memory demand and host capacity before changing the limit. Validate Compose syntax without printing the rendered secrets.

Terminal window
docker compose config --quiet
04

Roll out the single service and verify

Recovery

For a confirmed service-only configuration or image fix, use the approved deployment procedure. The example assumes dependencies are already healthy and may recreate the app container. Confirm it stays running or completes as expected, check its application health, and compare the restart count over time. If it regresses, restore the known-good Compose settings and image reference, then redeploy through the same process.

Terminal window
docker compose up -d --no-deps app
docker compose ps --all app
docker compose logs --tail 40 --timestamps app

References

Comments