Claude代码开发容器
带有Claude Code CLI和可配置MCP(模型上下文协议)服务器的Docker开发容器。为开发工作流而构建,在构建时内置MCP配置,用于干净的多容器部署。
快速开始
选择您的部署选项:
选项1:默认设置
# Create .env file
cp .env.example .env
# Edit .env to:
# - Add your GitHub token
# - Customize MCP_SERVERS (default: puppeteer,github)
docker-compose up -d claude-dev
docker exec -it claude-dev bash选项2:全栈(所有MCP服务器)
# Set GitHub token in .env first
echo "GITHUB_TOKEN=your_token_here" > .env
docker-compose --profile full up -d claude-full
docker exec -it claude-full bash选项3:自定义配置
# Configure in .env
echo "CUSTOM_MCP_SERVERS=puppeteer,filesystem" > .env
docker-compose --profile custom up -d claude-custom
docker exec -it claude-custom bash选项4:使用自定义参数直接构建
docker build --build-arg MCP_SERVERS=puppeteer,filesystem -t my-claude .
docker run -it --cap-add=SYS_ADMIN --security-opt=seccomp:unconfined my-claude然后在任何容器中:
claude auth # Authenticate once (if needed)
claude # Start Claude Code (with permission prompts)
claude-auto # Start Claude Code (auto-accept all permissions)
# MCP servers are configured automatically on first run配置
简单.env配置
只需编辑您的 .env 文件:
# Add any MCP servers you want (default: puppeteer,github)
MCP_SERVERS=puppeteer,github,filesystem,sqlite
# Add required tokens
GITHUB_TOKEN=ghp_your_token_here
# POSTGRES_URL=postgresql://localhost:5432/mydb
# BRAVE_API_KEY=your_api_key然后重建: docker-compose up -d --build claude-dev
预配置服务
| 服务 | MCP服务器 | 用例 |
|---|---|---|
claude-dev | 从 MCP_SERVERS in.env(默认:puppeteer,github) | 默认服务 |
claude-full | 从 MCP_SERVERS_FULL in.env | 全栈服务 |
claude-custom | 从 CUSTOM_MCP_SERVERS in.env | 自定义服务 |
自定义构建
# Web automation + file operations
docker build --build-arg MCP_SERVERS=puppeteer,filesystem -t claude-dev .
# Full stack with GitHub
docker build \
--build-arg MCP_SERVERS=puppeteer,filesystem,github \
--build-arg GITHUB_TOKEN=your_token \
-t claude-full .MCP设置
MCP服务器 自动配置 基于容器的启动 MCP_SERVERS 构建论点。无需手动设置!
验证配置
# Check configured servers
claude mcp list
# In Claude, use the /mcp command
/mcp手动设置(如果需要)
# Run the setup script manually
setup-mcp
# Or add servers individually
claude mcp add puppeteer --scope user -- npx -y @modelcontextprotocol/server-puppeteer使用示例
使用Puppeteer实现Web自动化
Navigate to https://example.com
Take a screenshot named "homepage"
Click the link with text "More information"
Fill the input field with placeholder "Search" with "test query"文件操作(使用文件系统服务器)
List files in the current directory
Read the contents of package.json
Create a new file called notes.txt with content "Hello World"GitHub操作(使用GitHub服务器+令牌)
Search for repositories about machine learning
Create a new repository called "my-project"
Get the contents of README.md from user/repo多容器部署
生产部署
# Build specific variants
docker build --build-arg MCP_SERVERS=puppeteer -t claude:web .
docker build --build-arg MCP_SERVERS=filesystem -t claude:files .
docker build --build-arg MCP_SERVERS=puppeteer,github --build-arg GITHUB_TOKEN=token -t claude:github .
# Deploy multiple instances
docker run -d --name web-dev --cap-add=SYS_ADMIN claude:web
docker run -d --name file-dev --cap-add=SYS_ADMIN claude:files
docker run -d --name github-dev --cap-add=SYS_ADMIN claude:github容器管理
# Default service
docker-compose up -d claude-dev
# Full stack
docker-compose --profile full up -d
# Custom configuration
docker-compose --profile custom up -d
# Stop all
docker-compose down
# Rebuild
docker-compose build --no-cache文件结构
dev_container/
├── dockerfile # Container with build-time MCP config
├── docker-compose.yml # Multi-service configuration
├── .env.example # Environment variables
├── .gitignore # Git ignore patterns
├── scripts/ # Container setup scripts
│ ├── entrypoint.sh # Auto-configures MCP on startup
│ └── setup-mcp.sh # Manual MCP setup script
└── workspace/ # Your working directory可用的MCP服务器
| 服务器 | 用途 | 要求 |
|---|---|---|
puppeteer | Web自动化、屏幕截图、表单填写 | 无(默认) |
filesystem | 工作区中的文件操作 | 无 |
github | GitHub API集成 | GITHUB_TOKEN 在.env中 |
GitHub MCP服务器设置
GitHub MCP服务器允许Claude与GitHub存储库、问题、PR等进行交互。
创建GitHub令牌
- 首选
- 使用以下作用域创建新令牌:
- 仓库 -完全控制私有存储库 - 阅读:org -阅读组织和团队成员 - read:用户 -读取用户配置文件数据 - 要点 -创建注册表
- 复制令牌(以开头
ghp_) - 增添
.env文件:
GITHUB_TOKEN=ghp_your_token_hereGitHub MCP使用示例
配置后,您可以要求Claude:
# Repository operations
- "Search for React repositories with more than 1000 stars"
- "Create a new repository called my-project"
- "Clone https://github.com/user/repo"
# Issues and PRs
- "List open issues in user/repo"
- "Create an issue titled 'Bug: XYZ not working'"
- "Review PR #123 in user/repo"
# Code search
- "Search for 'useState' in the React repository"
- "Find all TypeScript files in user/repo"
# Gists
- "Create a gist with this code snippet"
- "List my recent gists"身份验证持久性
您的Claude登录(包括Max订阅)会自动保存在Docker卷中:
claude-dev-auth-对于默认容器claude-full-auth-对于全堆叠集装箱claude-custom-auth-用于自定义配置
身份验证说明
- 身份验证在Docker卷中持久化
- 每个服务都有自己的身份验证卷(claude-dev-auth、claude-full-auth等)
- 要在容器之间共享身份验证,可以使用Docker volume命令
故障排除
身份验证问题
# Re-authenticate
claude auth
# Check auth status
claude config
# Verify auth persistence
docker volume ls | grep claudeWeb自动化问题
# Check Chromium installation
chromium --version
# Test with minimal flags
chromium --no-sandbox --headless --dump-dom https://example.comMCP配置
# Configure MCP servers (run once after authentication)
setup-mcp
# View configured servers
claude mcp list
# View server details
claude mcp get puppeteer
# Remove a server
claude mcp remove puppeteer
# Add custom server
claude mcp add myserver -- /path/to/server容器资源
确保Docker有足够的资源:
- 内存:建议2GB以上
- CPU:2+核,运行平稳
安全说明
- 容器以提升的权限运行以实现web自动化
- 为开发工作流启用了自动接受模式
- 保持GitHub令牌的安全,并使用最小权限
- 每个服务都有独立的身份验证和配置
