Stop a Docker Container From Exiting Immediately
A real devops problem you debug end to end in a live cloud workspace, then show on your portfolio. No tutorial, no toy app - a broken system that behaves like production.
The scenario
A teammate containerized a small web service, but the container won't stay running - docker run exits the moment it starts.
The broken code you start with
FROM python:3.12-slim
WORKDIR /app
COPY . .
CMD ["python", "app.py"] # app.py runs once and returns - the container exitsWhat this teaches you
What you did: docker logs <container> showed exec: "server.py": no such file. The Dockerfile CMD referenced a file that didn't exist (typo or stale rename). Fixed the CMD to point at the actual entrypoint file, rebuilt, and the container stayed up.
Why it matters: Containers run exactly one foreground process and exit when that process exits. A wrong filename, wrong path, or bad exec call = instant exit. The fix lives in docker logs, not in guessing.
In the real world: Production Dockerfiles use ENTRYPOINT ["./entrypoint.sh"] (exec form, not shell) for predictable signal handling, and CI builds the image and runs it to verify it stays up for at least a few seconds before merging.
What you'll practice
- Reading container logs and exit codes
- Understanding why a container needs a foreground process
- Fixing a Dockerfile so the service stays up
Why this impresses a hiring manager
- This is a real docker problem teams hit in production - not a synthetic puzzle.
- It shows you can diagnose and fix a DevOps issue in a live system end to end.
- It lands on your portfolio as a scenario a hiring manager can open and click through.
Corrected the Dockerfile CMD to reference the real entrypoint script so the container actually runs a process and stays up
Keep going
Build this project free
You're in a real cloud workspace in 30 seconds. Fix it, and it lands on your portfolio.
Start this project →