Skip to content

FAQ

Frequent questions about Dockerfiles: CMD vs ENTRYPOINT, ADD vs COPY, multi-stage.

CMD vs ENTRYPOINT?

ENTRYPOINT is the command; CMD is its default arguments. ENTRYPOINT ["node"], CMD ["app.js"] → runs node app.js. Override at runtime with docker run img other.js.

ADD vs COPY?

COPY copies files. ADD copies + auto-extracts local tarballs + fetches URLs. Prefer COPY; use ADD only when you need its magic.

How does multi-stage work?

Multiple FROM blocks. Each is a stage. COPY --from=builder /app/dist /app copies from one stage to another. Only the last stage is the final image.

Do I need a `.dockerignore`?

Yes. Without it, COPY . . includes node_modules, .git and 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.