contentintech
Cheatsheets/Dockerfile
DevOps

Dockerfile

Build smaller images with explicit layers and predictable startup.

Base and files

FROM node:22-alpineChoose a base image; pin a digest for reproducibility
WORKDIR /appSet the working directory for subsequent instructions
COPY package*.json ./Copy dependency manifests before source
RUN npm ci --omit=devInstall lockfile dependencies for a runtime image

Runtime

COPY . .Copy source after excluding unnecessary files with .dockerignore
ENV NODE_ENV=productionSet a runtime environment default
EXPOSE 3000Document the intended port; this does not publish it
CMD ["node", "server.js"]Use exec-form startup for cleaner signal handling

Build choices

FROM node:22-alpine AS buildName a build stage
COPY --from=build /app/dist ./distCopy artifacts from a previous stage
USER nodeDrop root privileges when filesystem permissions permit
docker build --target build -t app-build .Build a selected stage

Section navigation