How to Run Claude Code in Docker Container 2026

Written by Michael Lip · Solo founder of Zovo · $400K+ on Upwork · 100% JSS Join 50+ builders · More at zovo.one

The Workflow

Run Claude Code inside a Docker container for isolated, reproducible AI-assisted development. This approach provides sandboxed file access, consistent environments across machines, and safe experimentation without risk to your host system.

Expected time: 15 minutes Prerequisites: Docker 24+, Anthropic API key

Setup

1. Create the Dockerfile

# Dockerfile.claude-code
FROM node:20-slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    jq \
    python3 \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*

# Install Claude Code globally
RUN npm install -g @anthropic-ai/claude-code

# Create workspace directory
RUN mkdir -p /workspace && chown node:node /workspace

# Switch to non-root user
USER node
WORKDIR /workspace

# Set default shell
SHELL ["/bin/bash", "-c"]

# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s \
  CMD claude --version || exit 1

ENTRYPOINT ["claude"]

2. Build the Image

docker build -t claude-code:latest -f Dockerfile.claude-code .

This creates a reusable image with Claude Code and common development tools pre-installed.

3. Run with Project Volume Mount

# Interactive mode with your project mounted
docker run -it --rm \
  -v "$(pwd):/workspace" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest

Your project files are accessible inside the container at /workspace, and any changes Claude Code makes are reflected on your host filesystem.

4. Create a Docker Compose Configuration

# docker-compose.claude.yml
version: "3.9"

services:
  claude-code:
    build:
      context: .
      dockerfile: Dockerfile.claude-code
    volumes:
      - .:/workspace
      - claude-config:/home/node/.claude
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
    stdin_open: true
    tty: true
    working_dir: /workspace

  claude-code-readonly:
    build:
      context: .
      dockerfile: Dockerfile.claude-code
    volumes:
      - .:/workspace:ro
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
    stdin_open: true
    tty: true
    entrypoint: ["claude", "--print"]

volumes:
  claude-config:

The readonly service variant mounts your project as read-only for safe code review tasks.

5. Create a Shell Alias for Quick Access

# Add to ~/.zshrc or ~/.bashrc
alias claude-docker='docker run -it --rm \
  -v "$(pwd):/workspace" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest'

alias claude-docker-print='docker run --rm \
  -v "$(pwd):/workspace:ro" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest --print'

6. Verify

docker run --rm \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest --version
# Expected output:
# claude-code x.x.x

docker run --rm \
  -v "$(pwd):/workspace" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest --print "List files in /workspace"
# Expected output:
# Lists your current directory's files

Usage Example

Run Claude Code in Docker for a safe refactoring task:

# Start interactive session with project mounted
docker run -it --rm \
  -v ~/projects/my-api:/workspace \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest

# Inside the container, Claude Code has full access to /workspace
> Refactor all Express route handlers in src/routes/ to use
> async/await instead of .then() chains. Preserve error handling.

For CI/CD integration, use the non-interactive mode:

# Run a code review in CI
docker run --rm \
  -v "$(pwd):/workspace:ro" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:latest --print \
  "Review the code in src/auth/ for security issues. \
   Check for: SQL injection, XSS, insecure token handling. \
   Output as a JSON array of findings with file, line, severity, description."

Multi-language project setup with additional tools:

# Dockerfile.claude-code-full
FROM node:20-slim

RUN apt-get update && apt-get install -y \
    git curl jq python3 python3-pip \
    golang-go rustc cargo \
    && rm -rf /var/lib/apt/lists/*

RUN npm install -g @anthropic-ai/claude-code typescript tsx
RUN pip3 install --break-system-packages ruff pytest

USER node
WORKDIR /workspace
ENTRYPOINT ["claude"]
# Build and run the full-stack variant
docker build -t claude-code:full -f Dockerfile.claude-code-full .
docker run -it --rm \
  -v "$(pwd):/workspace" \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  claude-code:full

Common Issues

Why This Matters

Docker isolation guarantees Claude Code cannot access files outside your mounted project directory. Teams use this approach to enforce security boundaries while still benefiting from AI-assisted development.