Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
beginner Free Troubleshooting · ⏱ 25 min

Fix a Container Restart Loop

Scenario

A service is stuck in a crash-restart cycle — `docker ps` shows it “Restarting” over and over. You need to interpret the exit code, read the logs, and fix the entrypoint/config so it stays up.

Learning objectives

  • Identify the restart loop
  • Read the exit code and logs
  • Determine the root cause
  • Apply a fix so the container stays running

Before you start

Required software: Docker Engine 24+ or Docker Desktop

Prerequisites: Docker Fundamentals path

  1. Download and unzip the lab.
  2. Start it: docker compose up -d.
  3. Watch it flap: watch docker ps.

Instructions

1. Confirm the loop

See the container flapping and note the status:

docker ps -a

2. Read the exit code + logs

The exit code is the biggest clue:

docker inspect looping-svc --format '{{.State.ExitCode}}'
docker logs looping-svc

3. Fix the cause

The planted cause is in the entrypoint/command or a required env/file. Correct it and re-apply.

4. Validate

bash validation/validate.sh

Hints

💡 What does the exit code mean?

Exit 127 = command not found; 126 = not executable; 1/2 = app-level error; 137 = SIGKILL (often OOM). Match the code to the class of problem before reading logs.

💡 Logs are empty

If the process dies before logging, the entrypoint itself is likely wrong (typo’d binary, missing file). Check the command/entrypoint in the compose file.

Validate your work

From the lab folder, run:

bash validation/validate.sh

The script reads only your local Docker state, never transmits data off your machine, and returns a status code:

  • 0 — Lab successfully completed
  • 1 — Validation failed
  • 2 — Required dependency missing
  • 3 — Lab environment not running
  • 4 — Configuration error
  • 5 — Validation timed out

Note: validation targets Linux first. On Docker Desktop (macOS/Windows) some host-level checks (e.g. disk usage) may report differently; each script documents its limitations.

Solution

The full solution + troubleshooting explanation is available to signed-in learners. Try to solve it first — that’s where the learning is.

Reset the lab

  • docker compose down && docker compose up -d from the original files.

Interview questions

  • What does exit code 137 usually indicate?
  • How do you distinguish an application crash from a bad entrypoint?
  • How do restart policies (`no`, `on-failure`, `always`) change this behavior?

Finished this lab?

Sign in to record your completion and track progress across the path. Completion is recorded server-side.

Related labs