Tool
Docker
Application packaging as reproducible containers; Dockerfile, multi-stage builds and composition with docker-compose.
Key points
- ▸Image vs container: an image is an immutable template; a container is a running instance of that image.
- ▸Multi-stage builds (FROM build AS ... + FROM runtime) drop the toolchain and shrink the final image.
- ▸Each RUN / COPY creates a cacheable layer; ordering from least to most volatile speeds up rebuilds.
- ▸.dockerignore keeps node_modules, .git and secrets out of the build context.
- ▸Networks: bridge (default), host (high throughput, no isolation), custom for microservices with internal DNS.
- ▸Compose declares services + volumes + networks in a single reproducible YAML for local environments.
Code
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
FROM node:22-alpine AS runtime
WORKDIR /app
COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public
COPY --from=build /app/package.json ./
EXPOSE 3000
CMD ["pnpm", "start"]
Multi-stage build for a Next.js app: the toolchain stays out of the runtime.