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.
More on Write-a-Dockerfile tasks
Write a production Dockerfile for a Node.js API using a multi-stage build.IntermediateWrite a Dockerfile for a Python Flask app that runs with gunicorn as a non-root user.BeginnerWrite a Dockerfile for a Go service that produces a tiny image (under 20 MB).IntermediateWrite a multi-stage Dockerfile for a Java Spring Boot app built with Maven.IntermediateWrite a Dockerfile for a static React site served by Nginx.BeginnerThis Dockerfile rebuilds dependencies on every code change. Fix it.Beginner