CodePark/ questions / Dockerfile instructions
START PRACTICINGPRACTICE
Backend question · Docker › Dockerfile instructions

Given this Dockerfile, what process runs for docker run myapp --port 4000?

FROM node:22-slim
WORKDIR /app
COPY . .
ENTRYPOINT ["node", "server.js"]
CMD ["--port", "3000"]
node server.js --port 4000

The process is node server.js --port 4000. Arguments after the image name replace CMD completely. Docker then adds them to the end of the exec-form ENTRYPOINT. (Exec form is the JSON array form, like ["node", "server.js"].)

"
node server.js --port 3000 --port 4000" is wrong. The new arguments are not added after the old CMD. They replace it.

"
--port 4000 (the container fails to start)" is also wrong. The arguments do not replace ENTRYPOINT. To replace ENTRYPOINT, you need the --entrypoint flag.