Docker

Lesson 08

ENTRYPOINT, CMD, and signals

Use exec-form commands and keep startup wrappers signal-safe so containers stop gracefully.

Good Code

Dockerfile
FROM node:22-alpine

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY server.js ./server.js

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

Bad Code

Dockerfile
FROM node:22-alpine

WORKDIR /app
COPY . .
RUN npm install

CMD npm start

Review Notes

What to review

Good Code

The good version uses exec form, so the application process receives termination signals directly.

Bad Code

The bad version uses shell form. The shell can become PID 1 and make signal forwarding and graceful shutdown less predictable.

Takeaways

  • The process started by Docker should receive signals directly and shut down predictably.