Claude Code Docker VSCode Setup Guide
Running Claude Code inside Docker containers through VSCode Dev Containers gives you reproducible development environments with full AI assistance. This guide covers the complete setup from Dockerfile configuration to CLAUDE.md integration, so every team member gets the same Claude-powered experience regardless of their host OS.
The Problem
Developers using Claude Code on their local machines hit inconsistencies when switching between projects or collaborating with teammates on different operating systems. Docker Dev Containers solve environment drift, but getting Claude Code to work properly inside them requires specific configuration for authentication, file permissions, and MCP server connectivity.
Quick Solution
-
Install the VSCode Dev Containers extension and Docker Desktop.
-
Create
.devcontainer/devcontainer.jsonin your project root:
{
"name": "Claude Code Dev",
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {}
},
"postCreateCommand": "npm install -g @anthropic-ai/claude-code",
"mounts": [
"source=${localEnv:HOME}/.claude,target=/home/node/.claude,type=bind,consistency=cached"
],
"remoteEnv": {
"ANTHROPIC_API_KEY": "${localEnv:ANTHROPIC_API_KEY}"
},
"forwardPorts": []
}
-
Open the Command Palette and run Dev Containers: Reopen in Container.
-
Open the integrated terminal and run
claudeto verify the installation. -
Place your
CLAUDE.mdfile in the project root so it is available inside the container automatically.
How It Works
VSCode Dev Containers run your entire development environment inside a Docker container while keeping the editor UI on your host machine. When you mount your ~/.claude directory into the container, Claude Code picks up your authentication tokens and session history without requiring re-authentication.
The postCreateCommand installs Claude Code globally inside the container on first build. Because the container filesystem is ephemeral, this runs each time you rebuild, but cached layers keep it fast.
CLAUDE.md files work normally since they live in the project root, which is automatically mounted as the container workspace. MCP servers defined in your project-level .mcp.json will also be available, though servers that depend on host-level binaries need to be installed inside the container image.
Hooks configured in .claude/hooks/ execute inside the container, giving them access to the same toolchain your code uses. This is especially useful for pre-commit hooks that run linters or formatters.
Common Issues
Authentication fails inside the container. Ensure the ~/.claude directory mount is correct and the ANTHROPIC_API_KEY environment variable is forwarded. Check with echo $ANTHROPIC_API_KEY inside the container terminal.
MCP servers cannot connect. If your MCP server runs on the host machine, you need to forward the port into the container or run the MCP server inside the container itself. Add the server port to forwardPorts in devcontainer.json.
File permission errors on mounted volumes. The container user UID must match your host user UID. Add "remoteUser": "node" and ensure the mount target directory is owned by that user. Alternatively, use "updateRemoteUserUID": true.
Example CLAUDE.md Section
# Docker Dev Container Project
## Environment
- Runtime: Node.js 20 inside devcontainer
- Package manager: pnpm (installed via postCreateCommand)
- Database: PostgreSQL via docker-compose service
## Rules
- All commands run inside the container terminal
- Never modify files in /node_modules or /dist
- Run `pnpm test` before suggesting any commit
- Use relative imports, not absolute paths
## MCP Servers
- Database MCP available on localhost:5433
- File search uses built-in grep (no ripgrep in container)
## Container Notes
- Rebuild container after changing Dockerfile
- Environment variables come from .env.local on host
- Port 3000 is forwarded for dev server
Best Practices
- Pin your container image version instead of using
latestto prevent unexpected breakages when Claude Code or dependencies update. - Cache npm global installs by adding a Docker volume for
/home/node/.npmsopostCreateCommandcompletes faster on rebuilds. - Use docker-compose for services like databases and Redis alongside your dev container rather than installing them inside the container image.
- Keep CLAUDE.md container-aware by documenting which tools are available inside the container versus on the host.
- Forward only necessary ports to minimize the attack surface and avoid port conflicts between multiple dev containers.
Related Reading
- Claude Code Docker Compose Development Workflow
- Claude Code Docker Build Failed Fix
- Claude Code MCP Server Setup
Built by theluckystrike. More at zovo.one