|
| 1 | +# Gemini CLI Docker |
| 2 | + |
| 3 | +Run [Google Gemini CLI](https://github.com/google-gemini/gemini-cli) in a Docker container. Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. |
| 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 GOOGLE_API_KEY=your-key \ |
| 12 | + ungb/gemini-cli |
| 13 | +``` |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- [Docker](https://docs.docker.com/get-docker/) installed |
| 18 | +- [Google API key](https://aistudio.google.com/apikey) (free) or Google account |
| 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 GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 29 | + ungb/gemini-cli |
| 30 | + |
| 31 | +# With persistent config (remembers settings between runs) |
| 32 | +docker run -it --rm \ |
| 33 | + -v $(pwd):/workspace \ |
| 34 | + -v gemini-config:/home/coder/.gemini \ |
| 35 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 36 | + ungb/gemini-cli |
| 37 | + |
| 38 | +# With git/ssh support |
| 39 | +docker run -it --rm \ |
| 40 | + -v $(pwd):/workspace \ |
| 41 | + -v gemini-config:/home/coder/.gemini \ |
| 42 | + -v ~/.ssh:/home/coder/.ssh:ro \ |
| 43 | + -v ~/.gitconfig:/home/coder/.gitconfig:ro \ |
| 44 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 45 | + ungb/gemini-cli |
| 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/gemini-cli-docker/main/docker-compose.yml |
| 54 | +``` |
| 55 | + |
| 56 | +2. Create a `.env` file with your API key: |
| 57 | + |
| 58 | +```bash |
| 59 | +echo "GOOGLE_API_KEY=your-key-here" > .env |
| 60 | +``` |
| 61 | + |
| 62 | +3. Run: |
| 63 | + |
| 64 | +```bash |
| 65 | +docker compose run --rm gemini |
| 66 | +``` |
| 67 | + |
| 68 | +### Run a Specific Command |
| 69 | + |
| 70 | +```bash |
| 71 | +# Run gemini with a prompt |
| 72 | +docker run -it --rm \ |
| 73 | + -v $(pwd):/workspace \ |
| 74 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 75 | + ungb/gemini-cli \ |
| 76 | + gemini "explain this codebase" |
| 77 | + |
| 78 | +# Check version |
| 79 | +docker run -it --rm ungb/gemini-cli gemini --version |
| 80 | + |
| 81 | +# Run with specific model |
| 82 | +docker run -it --rm \ |
| 83 | + -v $(pwd):/workspace \ |
| 84 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 85 | + -e GEMINI_MODEL=gemini-2.5-pro \ |
| 86 | + ungb/gemini-cli |
| 87 | +``` |
| 88 | + |
| 89 | +## Authentication |
| 90 | + |
| 91 | +### Option 1: API Key (Recommended for Docker) |
| 92 | + |
| 93 | +Get a free API key from [Google AI Studio](https://aistudio.google.com/apikey) and pass it as an environment variable: |
| 94 | + |
| 95 | +```bash |
| 96 | +-e GOOGLE_API_KEY=AI... |
| 97 | +``` |
| 98 | + |
| 99 | +**Free tier includes:** |
| 100 | +- 60 requests per minute |
| 101 | +- 1,000 requests per day |
| 102 | +- Access to Gemini 2.5 Pro with 1M token context window |
| 103 | + |
| 104 | +### Option 2: Google Account Login |
| 105 | + |
| 106 | +For browser-based authentication (requires host network): |
| 107 | + |
| 108 | +```bash |
| 109 | +docker run -it --rm \ |
| 110 | + --network host \ |
| 111 | + -v $(pwd):/workspace \ |
| 112 | + -v gemini-config:/home/coder/.gemini \ |
| 113 | + ungb/gemini-cli |
| 114 | +``` |
| 115 | + |
| 116 | +Then follow the prompts to authenticate with your Google account. |
| 117 | + |
| 118 | +### Option 3: Vertex AI |
| 119 | + |
| 120 | +For enterprise users with Google Cloud: |
| 121 | + |
| 122 | +```bash |
| 123 | +docker run -it --rm \ |
| 124 | + -v $(pwd):/workspace \ |
| 125 | + -v ~/.config/gcloud:/home/coder/.config/gcloud:ro \ |
| 126 | + -e GOOGLE_CLOUD_PROJECT=your-project \ |
| 127 | + ungb/gemini-cli |
| 128 | +``` |
| 129 | + |
| 130 | +## Volume Mounts |
| 131 | + |
| 132 | +| Mount | Purpose | |
| 133 | +|-------|---------| |
| 134 | +| `/workspace` | Your project directory (required) | |
| 135 | +| `/home/coder/.gemini` | Gemini config and cache (optional, for persistence) | |
| 136 | +| `/home/coder/.ssh` | SSH keys for git operations (optional, read-only) | |
| 137 | +| `/home/coder/.gitconfig` | Git configuration (optional, read-only) | |
| 138 | +| `/home/coder/.config/gcloud` | Google Cloud credentials (optional, for Vertex AI) | |
| 139 | + |
| 140 | +## Environment Variables |
| 141 | + |
| 142 | +| Variable | Required | Description | |
| 143 | +|----------|----------|-------------| |
| 144 | +| `GOOGLE_API_KEY` | Yes* | Google AI Studio API key | |
| 145 | +| `GOOGLE_CLOUD_PROJECT` | No | GCP project ID (for Vertex AI) | |
| 146 | +| `GOOGLE_CLOUD_REGION` | No | GCP region (for Vertex AI) | |
| 147 | +| `GEMINI_MODEL` | No | Model to use (default: gemini-2.5-pro) | |
| 148 | + |
| 149 | +*Required unless using Google account login or Vertex AI |
| 150 | + |
| 151 | +## Features |
| 152 | + |
| 153 | +Gemini CLI includes built-in tools for: |
| 154 | +- Google Search grounding |
| 155 | +- File operations |
| 156 | +- Shell commands |
| 157 | +- Web fetching |
| 158 | +- MCP (Model Context Protocol) extensions |
| 159 | + |
| 160 | +## Building Locally |
| 161 | + |
| 162 | +```bash |
| 163 | +git clone https://github.com/ungb/gemini-cli-docker.git |
| 164 | +cd gemini-cli-docker |
| 165 | +docker build -t gemini-cli . |
| 166 | +``` |
| 167 | + |
| 168 | +## Troubleshooting |
| 169 | + |
| 170 | +### Permission Denied on Mounted Files |
| 171 | + |
| 172 | +The container runs as user `coder` (UID 1000). If you have permission issues: |
| 173 | + |
| 174 | +```bash |
| 175 | +# Run with your user ID |
| 176 | +docker run -it --rm \ |
| 177 | + --user $(id -u):$(id -g) \ |
| 178 | + -v $(pwd):/workspace \ |
| 179 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 180 | + ungb/gemini-cli |
| 181 | +``` |
| 182 | + |
| 183 | +### Git Operations Failing |
| 184 | + |
| 185 | +Ensure SSH keys are mounted and git is configured: |
| 186 | + |
| 187 | +```bash |
| 188 | +docker run -it --rm \ |
| 189 | + -v $(pwd):/workspace \ |
| 190 | + -v ~/.ssh:/home/coder/.ssh:ro \ |
| 191 | + -v ~/.gitconfig:/home/coder/.gitconfig:ro \ |
| 192 | + -e GOOGLE_API_KEY=$GOOGLE_API_KEY \ |
| 193 | + ungb/gemini-cli |
| 194 | +``` |
| 195 | + |
| 196 | +### Authentication Issues |
| 197 | + |
| 198 | +Make sure your API key is valid: |
| 199 | + |
| 200 | +```bash |
| 201 | +# Test your API key |
| 202 | +curl -H "x-goog-api-key: $GOOGLE_API_KEY" \ |
| 203 | + "https://generativelanguage.googleapis.com/v1beta/models" |
| 204 | +``` |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +MIT License - see [LICENSE](LICENSE) |
| 209 | + |
| 210 | +## Links |
| 211 | + |
| 212 | +- [Gemini CLI Documentation](https://geminicli.com/) |
| 213 | +- [Gemini CLI GitHub](https://github.com/google-gemini/gemini-cli) |
| 214 | +- [Google AI Studio](https://aistudio.google.com/) |
| 215 | +- [Get API Key](https://aistudio.google.com/apikey) |
0 commit comments