Your app ignores `docker stop` and takes exactly 10 seconds to die. Why and what do you change?
IntermediateScenarioImage design and Dockerfile decisions
Answer
Situation read → The process is not receiving or handling SIGTERM, so Docker sends SIGKILL after the grace period.
What I'd do →
- Check
docker inspect -f '{{.Config.Entrypoint}} {{.Config.Cmd}}' cfor shell form (/bin/sh -c ...). - Switch to exec form or add
execin the wrapper script. - If the app does not reap zombies or handle signals, run with
--init(tini). - Handle SIGTERM in the app (graceful shutdown) and optionally set
STOPSIGNALand--stop-timeout.
Why → PID 1 in a container gets no default signal handlers from the kernel; it must install its own.
Interview tip → Mention docker run --init as the zero-code fix.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner