Docker Compose Tip #46: Build args vs environment variables

Build args and environment variables both pass values to your containers, but they work at different times and serve different purposes. Mixing them up is a common source of confusion. Build args: build-time only Build args are available during docker build and are not present in the running container: services: app: build: context: . args: NODE_VERSION: "20" APP_VERSION: "2.1.0" In the Dockerfile, they’re consumed with ARG: ...

March 30, 2026 · 3 min · 471 words · Guillaume Lours

Docker Compose Tip #45: Multi-stage builds with target

Multi-stage Dockerfiles let you define multiple build stages. With the target option in Compose, you can choose which stage to build — giving you different images from the same Dockerfile. A multi-stage Dockerfile # Stage 1: dependencies FROM node:20-slim AS deps WORKDIR /app COPY package*.json ./ RUN npm ci # Stage 2: development (with dev dependencies and tools) FROM deps AS dev RUN npm install --include=dev COPY . . CMD ["npm", "run", "dev"] # Stage 3: build FROM deps AS build COPY . . RUN npm run build # Stage 4: production (minimal) FROM node:20-slim AS production WORKDIR /app COPY --from=build /app/dist ./dist COPY --from=deps /app/node_modules ./node_modules CMD ["node", "dist/index.js"] Targeting stages in Compose Use target to pick which stage to build: ...

March 27, 2026 · 2 min · 354 words · Guillaume Lours

Docker Compose Tip #32: Build contexts and dockerignore patterns

Speed up builds and reduce image size by managing build contexts effectively. Don’t send unnecessary files to the Docker daemon! Understanding build context The build context is what gets sent to Docker daemon: services: app: build: . # Current directory is the context # Everything in . gets sent to daemon! Check your context size: # See what's being sent docker build --no-cache . 2>&1 | grep "Sending build context" # Output: Sending build context to Docker daemon 458.2MB 😱 Custom build contexts Specify different contexts for different services: ...

February 25, 2026 · 3 min · 433 words · Guillaume Lours

Docker Compose Tip #23: Multi-platform builds with platforms

Build once, run everywhere! Create images that work on ARM Macs, Intel servers, and Raspberry Pi with a single build command. Configure multi-arch builder Docker Desktop handles this by default. For other Docker installations, set up buildx: # Only needed if not using Docker Desktop # Create and use a new builder docker buildx create --name multiarch --use # Verify available platforms docker buildx ls Configure platforms Specify target architectures in your compose file: ...

February 4, 2026 · 3 min · 470 words · Guillaume Lours

Docker Compose Tip #12: Using target to specify build stages

One Dockerfile, multiple environments. Use target to build only the stage you need - faster builds, smaller images, cleaner separation. The basics Multi-stage Dockerfile: # Development stage FROM node:20-alpine AS development WORKDIR /app COPY package*.json ./ RUN npm install COPY . . CMD ["npm", "run", "dev"] # Production stage FROM node:20-alpine AS production WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . RUN npm run build CMD ["npm", "start"] Target specific stages in compose.yml: ...

January 20, 2026 · 2 min · 313 words · Guillaume Lours