DevOps EngineerJuniordockercontainersdockerfile

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.

Level
Junior
Time
~20 min
Cost
Free

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

Dockerfile (the container exits on start)
FROM python:3.12-slim
WORKDIR /app
COPY . .
CMD ["python", "app.py"]   # app.py runs once and returns - the container exits

What 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

Why this impresses a hiring manager

On your portfolio, this becomes

Corrected the Dockerfile CMD to reference the real entrypoint script so the container actually runs a process and stays up

Keep going

Fix the Nginx 502 Bad GatewayDevOps projectDevOps roadmapStep by step to hiredDevOps interview questionsSTAR answersAll DevOps projectsProjects hub

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 →