|
| 1 | +# Claude Code Docker |
| 2 | + |
| 3 | +Run [Claude Code](https://github.com/anthropics/claude-code) CLI in a Docker container. Claude Code is Anthropic's agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Pull and run (replace with your API key) |
| 9 | +docker run -it --rm \ |
| 10 | + -v $(pwd):/workspace \ |
| 11 | + -e ANTHROPIC_API_KEY=your-key \ |
| 12 | + ungb/claude-code |
| 13 | +``` |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- [Docker](https://docs.docker.com/get-docker/) installed |
| 18 | +- [Anthropic API key](https://console.anthropic.com/) or Claude account for OAuth |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +### Using Docker Run |
| 23 | + |
| 24 | +```bash |
| 25 | +# Basic usage with API key |
| 26 | +docker run -it --rm \ |
| 27 | + -v $(pwd):/workspace \ |
| 28 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 29 | + ungb/claude-code |
| 30 | + |
| 31 | +# With persistent config (remembers settings between runs) |
| 32 | +docker run -it --rm \ |
| 33 | + -v $(pwd):/workspace \ |
| 34 | + -v claude-config:/home/coder/.claude \ |
| 35 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 36 | + ungb/claude-code |
| 37 | + |
| 38 | +# With git/ssh support |
| 39 | +docker run -it --rm \ |
| 40 | + -v $(pwd):/workspace \ |
| 41 | + -v claude-config:/home/coder/.claude \ |
| 42 | + -v ~/.ssh:/home/coder/.ssh:ro \ |
| 43 | + -v ~/.gitconfig:/home/coder/.gitconfig:ro \ |
| 44 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 45 | + ungb/claude-code |
| 46 | +``` |
| 47 | + |
| 48 | +### Using Docker Compose |
| 49 | + |
| 50 | +1. Clone this repo or copy `docker-compose.yml` to your project: |
| 51 | + |
| 52 | +```bash |
| 53 | +curl -O https://raw.githubusercontent.com/ungb/claude-code-docker/main/docker-compose.yml |
| 54 | +``` |
| 55 | + |
| 56 | +2. Create a `.env` file with your API key: |
| 57 | + |
| 58 | +```bash |
| 59 | +echo "ANTHROPIC_API_KEY=your-key-here" > .env |
| 60 | +``` |
| 61 | + |
| 62 | +3. Run: |
| 63 | + |
| 64 | +```bash |
| 65 | +docker compose run --rm claude |
| 66 | +``` |
| 67 | + |
| 68 | +### Run a Specific Command |
| 69 | + |
| 70 | +```bash |
| 71 | +# Run claude with arguments |
| 72 | +docker run -it --rm \ |
| 73 | + -v $(pwd):/workspace \ |
| 74 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 75 | + ungb/claude-code \ |
| 76 | + claude "explain this codebase" |
| 77 | + |
| 78 | +# Check version |
| 79 | +docker run -it --rm ungb/claude-code claude --version |
| 80 | + |
| 81 | +# Run health check |
| 82 | +docker run -it --rm \ |
| 83 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 84 | + ungb/claude-code \ |
| 85 | + claude doctor |
| 86 | +``` |
| 87 | + |
| 88 | +## Authentication |
| 89 | + |
| 90 | +### Option 1: API Key (Recommended for Docker) |
| 91 | + |
| 92 | +Get an API key from [Anthropic Console](https://console.anthropic.com/) and pass it as an environment variable: |
| 93 | + |
| 94 | +```bash |
| 95 | +-e ANTHROPIC_API_KEY=sk-ant-... |
| 96 | +``` |
| 97 | + |
| 98 | +### Option 2: OAuth Login |
| 99 | + |
| 100 | +For browser-based OAuth (requires host network): |
| 101 | + |
| 102 | +```bash |
| 103 | +docker run -it --rm \ |
| 104 | + --network host \ |
| 105 | + -v $(pwd):/workspace \ |
| 106 | + -v claude-config:/home/coder/.claude \ |
| 107 | + ungb/claude-code \ |
| 108 | + claude login |
| 109 | +``` |
| 110 | + |
| 111 | +## Volume Mounts |
| 112 | + |
| 113 | +| Mount | Purpose | |
| 114 | +|-------|---------| |
| 115 | +| `/workspace` | Your project directory (required) | |
| 116 | +| `/home/coder/.claude` | Claude config and cache (optional, for persistence) | |
| 117 | +| `/home/coder/.ssh` | SSH keys for git operations (optional, read-only) | |
| 118 | +| `/home/coder/.gitconfig` | Git configuration (optional, read-only) | |
| 119 | + |
| 120 | +## Environment Variables |
| 121 | + |
| 122 | +| Variable | Required | Description | |
| 123 | +|----------|----------|-------------| |
| 124 | +| `ANTHROPIC_API_KEY` | Yes* | Your Anthropic API key | |
| 125 | +| `ANTHROPIC_API_BASE_URL` | No | Custom API endpoint (for proxies) | |
| 126 | + |
| 127 | +*Required unless using OAuth login |
| 128 | + |
| 129 | +## Building Locally |
| 130 | + |
| 131 | +```bash |
| 132 | +git clone https://github.com/ungb/claude-code-docker.git |
| 133 | +cd claude-code-docker |
| 134 | +docker build -t claude-code . |
| 135 | +``` |
| 136 | + |
| 137 | +## Troubleshooting |
| 138 | + |
| 139 | +### Permission Denied on Mounted Files |
| 140 | + |
| 141 | +The container runs as user `coder` (UID 1000). If you have permission issues: |
| 142 | + |
| 143 | +```bash |
| 144 | +# Run with your user ID |
| 145 | +docker run -it --rm \ |
| 146 | + --user $(id -u):$(id -g) \ |
| 147 | + -v $(pwd):/workspace \ |
| 148 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 149 | + ungb/claude-code |
| 150 | +``` |
| 151 | + |
| 152 | +### Git Operations Failing |
| 153 | + |
| 154 | +Ensure SSH keys are mounted and git is configured: |
| 155 | + |
| 156 | +```bash |
| 157 | +docker run -it --rm \ |
| 158 | + -v $(pwd):/workspace \ |
| 159 | + -v ~/.ssh:/home/coder/.ssh:ro \ |
| 160 | + -v ~/.gitconfig:/home/coder/.gitconfig:ro \ |
| 161 | + -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ |
| 162 | + ungb/claude-code |
| 163 | +``` |
| 164 | + |
| 165 | +### OAuth Login Not Working |
| 166 | + |
| 167 | +Use `--network host` to allow the OAuth callback: |
| 168 | + |
| 169 | +```bash |
| 170 | +docker run -it --rm \ |
| 171 | + --network host \ |
| 172 | + -v $(pwd):/workspace \ |
| 173 | + -v claude-config:/home/coder/.claude \ |
| 174 | + ungb/claude-code \ |
| 175 | + claude login |
| 176 | +``` |
| 177 | + |
| 178 | +## License |
| 179 | + |
| 180 | +MIT License - see [LICENSE](LICENSE) |
| 181 | + |
| 182 | +## Links |
| 183 | + |
| 184 | +- [Claude Code Documentation](https://docs.anthropic.com/claude-code) |
| 185 | +- [Anthropic Console](https://console.anthropic.com/) |
| 186 | +- [Claude Code GitHub](https://github.com/anthropics/claude-code) |
0 commit comments