Fix a Container Restart Loop
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
- Download and unzip the lab.
- Start it:
docker compose up -d. - Watch it flap:
watch docker ps.
Instructions
1. Confirm the loop
See the container flapping and note the status:
docker ps -a2. Read the exit code + logs
The exit code is the biggest clue:
docker inspect looping-svc --format '{{.State.ExitCode}}'
docker logs looping-svc3. 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.shHints
💡 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 completed1— Validation failed2— Required dependency missing3— Lab environment not running4— Configuration error5— 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 -dfrom 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.