Frequent questions about Dockerfiles: CMD vs ENTRYPOINT, ADD vs COPY, multi-stage.
- CMD vs ENTRYPOINT?
ENTRYPOINTis the command;CMDis its default arguments.ENTRYPOINT ["node"],CMD ["app.js"]→ runsnode app.js. Override at runtime withdocker run img other.js.- ADD vs COPY?
COPYcopies files.ADDcopies + auto-extracts local tarballs + fetches URLs. PreferCOPY; useADDonly when you need its magic.- How does multi-stage work?
Multiple
FROMblocks. Each is a stage.COPY --from=builder /app/dist /appcopies from one stage to another. Only the last stage is the final image.- Do I need a `.dockerignore`?
Yes. Without it,
COPY . .includesnode_modules,.gitand logs. The image grows 10×.- How to reduce image size?
Alpine/distroless base, multi-stage, group RUN commands, clean apt caches in the same RUN.