●WWDC — WWDC 2026 confirms Siri runs on Google Gemini; third-party handoff to ChatGPT is dropped, and Siri AI won't ship in the EU under the DMA at iOS 27●BILLING — 6 days until the Jun 15 change: Agent SDK, headless Claude Code, GitHub Actions, and third-party agents move to API-rate monthly credit●OUTAGE — claude.ai, Claude Code, and Cowork saw an outage (Jun). Scheduled runs are safest when built around fallbackModel and retries●DYNAMIC-WORKFLOWS — Dynamic workflows are on by default on Max/Team and the API, for codebase-wide bug hunts and independent verification●ULTRACODE — Claude Code's new ultracode setting sits in the effort menu, fixing effort to xhigh while Claude decides when to run a workflow●OPUS4.8 — Claude Opus 4.8 is settled in as the default across major plans, with stronger coding, agentic, and reasoning skills●WWDC — WWDC 2026 confirms Siri runs on Google Gemini; third-party handoff to ChatGPT is dropped, and Siri AI won't ship in the EU under the DMA at iOS 27●BILLING — 6 days until the Jun 15 change: Agent SDK, headless Claude Code, GitHub Actions, and third-party agents move to API-rate monthly credit●OUTAGE — claude.ai, Claude Code, and Cowork saw an outage (Jun). Scheduled runs are safest when built around fallbackModel and retries●DYNAMIC-WORKFLOWS — Dynamic workflows are on by default on Max/Team and the API, for codebase-wide bug hunts and independent verification●ULTRACODE — Claude Code's new ultracode setting sits in the effort menu, fixing effort to xhigh while Claude decides when to run a workflow●OPUS4.8 — Claude Opus 4.8 is settled in as the default across major plans, with stronger coding, agentic, and reasoning skills
Claude Code × Docker — DevContainers, Multi-Stage Builds, and Production Deployment
A practical guide to production-grade development workflows combining Claude Code and Docker. From DevContainer setup and multi-stage build optimization to GitHub Actions CI/CD and Kubernetes deployment — with practical code examples throughout.
Setup and context — Why Claude Code × Docker Is Such a Powerful Combination
Container technology is an essential part of modern software development. Yet many developers still struggle with questions like "How should I structure my Dockerfile?", "DevContainer configuration is too complex", or "I keep running into issues when moving to production."
Claude Code dramatically solves these Docker-related challenges. You can ask it to optimize your Dockerfile in natural language, paste error messages directly and let it diagnose the cause, or automate the generation of complex Kubernetes YAML.
This article walks you through a production-grade development and deployment workflow combining Claude Code and Docker — step by step, with real code examples. We'll cover everything from DevContainer setup to multi-stage builds, Docker Compose local development environments, GitHub Actions CI/CD, and production deployment to Kubernetes or Fly.io.
This guide is designed for intermediate-to-advanced engineers who have basic Docker knowledge but haven't yet taken the leap into production operations. With Claude Code, you'll compress work that used to take days into hours.
DevContainer × Claude Code — Build a Reproducible Dev Environment in 5 Minutes
What Is DevContainer?
DevContainer is a mechanism used with VS Code or GitHub Codespaces that lets you define your development environment as code. Every team member works in an identical environment, eliminating the classic "it works on my machine" problem.
With Claude Code, you can generate and optimize .devcontainer/devcontainer.json files using natural language.
Generating a DevContainer with Claude Code
Run the following from your project root:
# Example Claude Code requestclaude "Create a devcontainer.json for a project using Node.js 22 + TypeScript + PostgreSQL 16.Also run npm install in the postCreateCommand."
Example generated .devcontainer/devcontainer.json:
Solving Common DevContainer Issues with Claude Code
If your DevContainer won't start, paste the error message directly into Claude Code:
claude "My DevContainer won't start with this error. Please identify the cause and fix:[error] failed to solve: failed to read dockerfile: open .devcontainer/Dockerfile: no such file or directory"
Claude Code will immediately identify the problem and propose either generating the missing Dockerfile or fixing the devcontainer.json.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦If you've been stuck on DevContainer configuration, you'll be able to set up a seamless Claude Code integration environment starting today
✦You'll learn multi-stage builds, Docker Compose, and security hardening patterns that you can apply directly to your own projects
✦You'll be able to eliminate manual deployment work by building a GitHub Actions × Docker × Claude Code automation pipeline
Secure payment via Stripe · Cancel anytime
Multi-Stage Builds — Minimizing Your Production Image
Why Multi-Stage Builds Matter
A Node.js app packaged naively into Docker — including node_modules — can easily reach several gigabytes. Production environments need lightweight images containing only the built artifacts.
Multi-stage builds separate the build environment from the runtime environment, reducing production images to under 100MB.
Generating a Multi-Stage Dockerfile with Claude Code
claude "Create a multi-stage Dockerfile for a Next.js 15 app with:- Build stage: node:22-alpine base- Production stage: node:22-alpine (distroless optional)- Non-root user for security- Minimal setup using .next/standalone- ARG to accept NODE_ENV"
Example generated Dockerfile:
# ──────────────────────────────────# Stage 1: Install dependencies# ──────────────────────────────────FROM node:22-alpine AS depsRUN apk add --no-cache libc6-compatWORKDIR /app# Copy only package files first (maximizes cache hits)COPY package.json package-lock.json* ./RUN npm ci --only=production --ignore-scripts# ──────────────────────────────────# Stage 2: Build# ──────────────────────────────────FROM node:22-alpine AS builderWORKDIR /appCOPY --from=deps /app/node_modules ./node_modulesCOPY . .# Assumes output: 'standalone' is set in next.config.tsENV NEXT_TELEMETRY_DISABLED=1RUN npm run build# ──────────────────────────────────# Stage 3: Production runner (minimal size)# ──────────────────────────────────FROM node:22-alpine AS runnerWORKDIR /appARG NODE_ENV=productionENV NODE_ENV=${NODE_ENV}ENV NEXT_TELEMETRY_DISABLED=1ENV PORT=3000# Security: create a non-root userRUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs# Copy only the files needed for standalone outputCOPY --from=builder /app/public ./publicCOPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/staticUSER nextjsEXPOSE 3000HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1CMD ["node", "server.js"]
This Dockerfile keeps the final image size to approximately 80–120MB — about a 90% reduction compared to a development image that includes node_modules.
Verifying Image Size
# Build and checkdocker build -t myapp:prod .docker images myapp# Expected output:# REPOSITORY TAG IMAGE ID CREATED SIZE# myapp prod a1b2c3d4e5f6 2 minutes ago 118MB
Docker Compose — Building a Local Multi-Service Development Environment
Designing a Practical docker-compose.yml
Ask Claude Code to build a full-stack dev environment with a frontend, backend API, database, and Redis:
claude "Create a docker-compose.yml with:- Next.js frontend + Hono.js API + PostgreSQL + Redis- Volume mounts for hot reload- Health checks for each service- Environment variables loaded from .env.local- Separate profiles for development and CI"
# Start all services (hot reload enabled)docker compose up -d# View logs (all services)docker compose logs -f# View logs for a specific servicedocker compose logs -f api# Run DB migrationdocker compose run --rm migrate# Execute a command inside a containerdocker compose exec api npm run db:seed# Stop and clean updocker compose down -v # Also removes volumes
Debugging Containers with Claude Code — Solve Problems 10x Faster
Error-by-Error Troubleshooting
Pipe container logs directly to Claude Code for instant analysis:
# When errors occurdocker compose logs api 2>&1 | claude "Analyze this error and tell me how to fix it"
Common problems and how Claude Code helps solve them:
Problem 1: Port binding error
Error response from daemon: driver failed programming external connectivity:
Bind for 0.0.0.0:5432 failed: port is already allocated
Claude Code immediately proposes how to identify the conflicting process (lsof -i :5432) and suggests updating the port in docker-compose.yml.
Problem 2: Health check failure blocking dependent services
# Check health statusdocker compose ps# Inspect health check details for a specific containerdocker inspect --format='{{json .State.Health}}' myapp-db-1 | python3 -m json.tool
Problem 3: node_modules permission issues
Ask Claude Code:
claude "My Node.js Docker container throws:EACCES: permission denied on node_modules.How should I fix the Dockerfile for a non-root user setup?"
Container Resource Optimization
# Check memory usagedocker stats --no-stream# Run service with resource limitsdocker compose up -d --scale api=3
Pass docker stats output to Claude Code and ask it to "calculate optimal memory limit values" to streamline your production resource planning.
claude "Create a GitHub Actions CI/CD workflow that:- Builds and tests Docker images on push to main- Pushes to GHCR and deploys to Cloud Run on tag push- Uses caching to reduce build time- Includes a Trivy security scan"
With GHA caching, build times drop from ~5 minutes on first run to under 1 minute on subsequent runs.
Security Hardening — Protecting Your Production Containers
Strengthening Security with Claude Code
claude "Identify security issues in my current Dockerfile andcreate a CIS benchmark-compliant version.Focus on: non-root users, removing unnecessary packages, read-only filesystem."
# In Dockerfile — secret never lands in image layers or cacheRUN --mount=type=secret,id=api_key \ API_KEY=$(cat /run/secrets/api_key) npm run build:with-key
Automating Vulnerability Scans
# Scan with Trivy, then ask Claude Code to interpret resultstrivy image myapp:prod --format json | \ claude "Analyze this Trivy vulnerability report and list critical issues requiring immediate action, in priority order."
Kubernetes Production Deployment — Practical Manifest Design with Claude Code
Generating K8s Manifests
Kubernetes manifest creation is one of Claude Code's strongest suits:
claude "Create Kubernetes manifests with:- Deployment: 3 replicas, rolling update strategy- Service: ClusterIP (Ingress-only access)- HPA: scale out at 70% CPU (max 10 replicas)- PodDisruptionBudget: always maintain minimum 2 replicas- Resource requests and limits configured"
# Bulk-remove unused images and containersdocker system prune -af --volumes# Ask Claude Code to analyze the root causedf -h | claude "Analyze this disk usage and tell methe best ways to reduce Docker-related file sizes."
Error 2: Build Cache Not Working
# Check cache efficiencydocker build --progress=plain . 2>&1 | grep -E "CACHED|DONE"# Common cause: COPY instruction order is not optimized# Ask Claude Code to fix it:claude "Improve the cache efficiency of this Dockerfile.Optimize COPY instruction order to minimize rebuilds on code changes."
Error 3: OOM (Out of Memory) in Production Containers
# Check for OOM eventsdocker events --filter event=oom# Detailed memory usagedocker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"# Ask Claude Code for optimization guidanceclaude "My Node.js Docker container OOMs at 512MB.How should I tune --max-old-space-size and K8s resource limits?"
Summary
The Claude Code × Docker combination dramatically accelerates modern container development workflows. Here's a recap of the key points covered in this article:
DevContainer: Reproducible development environments for your entire team. Claude Code auto-generates configuration files.
Multi-stage builds: Production images under 100MB. Claude Code proposes the right Dockerfile architecture for your project.
Docker Compose: Declarative local multi-service environments. Claude Code handles error debugging too.
Security: CIS benchmark compliance via non-root users, read-only filesystems, and proper secret management.
Kubernetes / Fly.io: Scalable production deployments using Claude Code-generated manifests.
With Claude Code, infrastructure design and implementation work that used to take days now takes hours. Decisions like "which base image to use," "how to structure multi-stage builds," and "what resource limits to set in K8s" can all be delegated to Claude Code — freeing you to focus on application logic.
Start with DevContainer configuration, have a conversation with Claude Code, and take the path to production one step at a time.
Share
Thank You for Reading
Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.