Skip to content

Commit 33c76e5

Browse files
committed
Initial commit: Google Gemini CLI Docker container
- Dockerfile with Node 22 slim base and Gemini CLI - docker-compose.yml for easy local running - Entrypoint script with config initialization - Support for API key, Google account, and Vertex AI auth - GitHub Actions workflow for multi-arch builds - Comprehensive README with usage examples MIT License
0 parents  commit 33c76e5

9 files changed

Lines changed: 460 additions & 0 deletions

File tree

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Documentation
6+
README.md
7+
LICENSE
8+
9+
# Environment files
10+
.env
11+
.env.*
12+
13+
# Workspace
14+
workspace/
15+
16+
# GitHub
17+
.github/
18+
19+
# OS
20+
.DS_Store
21+
Thumbs.db

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Google API Key (get one at https://aistudio.google.com/apikey)
2+
GOOGLE_API_KEY=your-api-key-here
3+
4+
# Optional: For Vertex AI instead of AI Studio
5+
# GOOGLE_CLOUD_PROJECT=your-project-id
6+
# GOOGLE_CLOUD_REGION=us-central1
7+
8+
# Optional: Custom model
9+
# GEMINI_MODEL=gemini-2.5-pro
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: docker.io
15+
IMAGE_NAME: ungb/gemini-cli
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to Docker Hub
35+
if: github.event_name != 'pull_request'
36+
uses: docker/login-action@v3
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- name: Extract metadata
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=raw,value=latest,enable={{is_default_branch}}
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
platforms: linux/amd64,linux/arm64
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Environment files
2+
.env
3+
.env.local
4+
5+
# Workspace directory (user's code)
6+
workspace/
7+
8+
# OS files
9+
.DS_Store
10+
Thumbs.db
11+
12+
# IDE
13+
.idea/
14+
.vscode/
15+
*.swp
16+
*.swo

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM node:22-slim
2+
3+
LABEL maintainer="ungb"
4+
LABEL description="Google Gemini CLI in a Docker container"
5+
LABEL org.opencontainers.image.source="https://github.com/ungb/gemini-cli-docker"
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
git \
10+
curl \
11+
openssh-client \
12+
ca-certificates \
13+
jq \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Install Google Gemini CLI globally
17+
RUN npm install -g @google/gemini-cli
18+
19+
# Create non-root user for security
20+
RUN useradd -m -s /bin/bash coder \
21+
&& mkdir -p /home/coder/.gemini \
22+
&& chown -R coder:coder /home/coder
23+
24+
# Set up workspace directory
25+
RUN mkdir -p /workspace && chown coder:coder /workspace
26+
27+
# Copy entrypoint script
28+
COPY --chown=coder:coder entrypoint.sh /entrypoint.sh
29+
RUN chmod +x /entrypoint.sh
30+
31+
# Switch to non-root user
32+
USER coder
33+
WORKDIR /workspace
34+
35+
# Environment variables
36+
ENV HOME=/home/coder
37+
ENV GEMINI_CONFIG_DIR=/home/coder/.gemini
38+
39+
ENTRYPOINT ["/entrypoint.sh"]
40+
CMD ["gemini"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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

Comments
 (0)