Interview Prep/Docker/Image design and Dockerfile decisions

A service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?

BeginnerScenarioImage design and Dockerfile decisions
Answer

Situation read → Entrypoint scripts are common for config templating or migrations.

What I'd do →

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "server.js"]

End the script with exec "$@" so the app replaces the shell and becomes PID 1.

Why → ENTRYPOINT is the fixed executable, CMD is the default, overridable argument list. Without exec, SIGTERM goes to the shell and the app is killed after the 10 s timeout.

Interview tip → Always use exec form (JSON array), never shell form, for the main process.

All Docker questions Roadmap: Docker & containers

More on Image design and Dockerfile decisions