Using Docker BuildKit for Faster Builds
BuildKit is Docker's next-generation build engine that provides significant performance improvements through parallel execution, better caching, and advanced features like build secrets and SSH forwarding.
Enable BuildKit
Set the environment variable or configure the Docker daemon on your Breeze:
# Per-command
DOCKER_BUILDKIT=1 docker build -t my-app .
# Permanent (daemon.json)
sudo tee /etc/docker/daemon.json <<EOF
{ "features": { "buildkit": true } }
EOF
sudo systemctl restart docker
Multi-Stage Caching
BuildKit caches each stage independently, skipping unchanged layers:
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
FROM node:20-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=deps /app/node_modules ./node_modules
CMD ["node", "dist/server.js"]
Cache Mounts
Persist package manager caches across builds:
RUN --mount=type=cache,target=/root/.npm npm ci
Build Secrets
Safely pass secrets without embedding them in layers:
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker build --secret id=npmrc,src=$HOME/.npmrc -t my-app .
Parallel Builds
BuildKit automatically parallelizes independent stages, reducing total build time. Use docker buildx bake to build multiple images concurrently from a single configuration file.