docker build -t myapp:dev .By default Docker reads `./Dockerfile` and sends the current directory as build context.
High-value Dockerfile instructions, patterns, and build flags for reproducible and efficient image builds.
Core build invocation and essential Dockerfile instructions.
docker build -t myapp:dev .By default Docker reads `./Dockerfile` and sends the current directory as build context.
docker build -f Dockerfile.prod -t myapp:prod .Common for environment-specific builds.
FROM node:20-alpineEvery stage starts from a `FROM` instruction.
WORKDIR /appAvoid repetitive `cd` logic and make paths explicit.
COPY package*.json ./Use `.dockerignore` to keep build contexts lean.
RUN npm ciCommon for dependency installation and image preparation.
CMD ["node", "server.js"]Can be overridden at runtime.
ENTRYPOINT ["/usr/local/bin/app"]Often paired with `CMD` for default arguments.
EXPOSE 3000This does not publish ports by itself.
ENV NODE_ENV=productionValues become defaults at runtime unless overridden.
ARG NODE_VERSION=20Build args are available only during build unless copied into `ENV`.
LABEL org.opencontainers.image.source="https://github.com/acme/myapp"Useful for provenance, ownership, and automation.
Repeatable Dockerfile patterns for efficient, secure images.
Build artifacts in one stage and copy only runtime output into the final stage.
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY /app/dist /usr/share/nginx/htmlMulti-stage builds keep runtime images smaller and cleaner.
RUN addgroup -S app && adduser -S app -G app
USER appA common hardening practice for production images.
HEALTHCHECK CMD wget -qO- http://localhost:3000/health || exit 1Useful with orchestrators and compose health status.
COPY . /appAvoids extra `chown` layers in many images.
Copy dependency manifests before application code to maximize layer cache reuse.
COPY package*.json ./
RUN npm ci
COPY . .A classic Dockerfile optimization for JS apps.
node_modules
dist
.git
.env
coverageReducing context size speeds up builds and avoids leaking sensitive files.
Common build options used with Dockerfiles.
docker build --target build -t myapp:build .Useful for debugging or exporting builder-only images.
docker build --build-arg NODE_VERSION=20 -t myapp:dev .Great for version pinning and parameterized builds.
docker build --no-cache -t myapp:clean .Useful when cache corruption or stale dependencies are suspected.
docker build --pull -t myapp:dev .Good for CI pipelines that want refreshed base layers.
docker build --platform linux/amd64 -t myapp:amd64 .Often used together with Buildx or multi-platform workflows.
docker build --progress=plain -t myapp:dev .Helpful when debugging failing builds in CI.