Interview Prep/Real-World Interview/Write-a-Dockerfile tasks

Fix the PID 1 / signal problem: the container takes 10 seconds to stop.

IntermediateHands-onWrite-a-Dockerfile tasks
Answer

Given:

CMD npm start

Fixed:

CMD ["node", "server.js"]

If you need a shell wrapper, end it with exec "$@", or add an init:

docker run --init myapp

Key trick → Shell-form CMD runs /bin/sh -c, which becomes PID 1 and doesn't forward SIGTERM, so Docker waits the 10-second grace period and then sends SIGKILL. Exec form makes the app PID 1 directly. npm also doesn't forward signals reliably.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Dockerfile tasks