2026-03-27 17:26:11 -04:00
# opencode Docker
2026-03-27 17:13:14 -04:00
2026-03-27 17:26:11 -04:00
Docker image for running [OpenCode ](https://opencode.ai ) as a headless HTTP server.
## What is OpenCode?
2026-10-17 19:28:14 +00:00
OpenCode is an open source AI coding agent available as a terminal interface, desktop app, or IDE extension. This image ships OpenCode 2 and runs it in server mode (`opencode serve` ), exposing an HTTP API and web UI that clients can connect to.
2026-03-27 17:26:11 -04:00
## Pull
```bash
docker pull jcabillot/opencode
```
2026-10-17 19:28:14 +00:00
The image is rebuilt and pushed to Docker Hub automatically every night by the Gitea Actions pipeline.
2026-03-27 17:26:11 -04:00
## Build locally
```bash
docker build -t opencode .
```
## Run
2026-10-17 19:28:14 +00:00
The entrypoint is the `opencode` binary; pass `serve` to start the headless server:
2026-03-27 17:26:11 -04:00
```bash
2026-10-17 19:28:14 +00:00
docker run -it -p 4096:4096 jcabillot/opencode serve
2026-03-27 17:26:11 -04:00
```
2026-10-17 19:28:14 +00:00
The server listens on `127.0.0.1:4096` by default. To expose it on all interfaces:
2026-03-27 17:26:11 -04:00
```bash
2026-10-17 19:28:14 +00:00
docker run -it -p 4096:4096 jcabillot/opencode serve --hostname 0.0.0.0
2026-03-27 17:26:11 -04:00
```
### Mount a project
```bash
docker run -it -p 4096:4096 \
-v $( pwd ) :/home/opencode/project \
2026-10-17 19:28:14 +00:00
jcabillot/opencode serve --hostname 0.0.0.0
2026-03-27 17:26:11 -04:00
```
### Secure with a password
```bash
docker run -it -p 4096:4096 \
-e OPENCODE_SERVER_PASSWORD = your-password \
2026-10-17 19:28:14 +00:00
jcabillot/opencode serve --hostname 0.0.0.0
2026-03-27 17:26:11 -04:00
```
2026-10-17 19:28:14 +00:00
Authentication uses HTTP basic auth. The username is always `opencode` ; the password is read from `OPENCODE_SERVER_PASSWORD` (or `OPENCODE_PASSWORD` ). When neither is set, OpenCode 2 generates a random password and prints it to the log at startup — the server is never left unauthenticated.
2026-03-27 17:26:11 -04:00
## Troubleshooting helper
The image includes an `opencode-attach` wrapper in `PATH` that runs:
```bash
2026-10-17 19:28:14 +00:00
opencode --server " ${ OPENCODE_API_URL } "
2026-03-27 17:26:11 -04:00
```
Example:
```bash
export OPENCODE_SERVER_PASSWORD = your-password
export OPENCODE_API_URL = http://127.0.0.1:4096
opencode-attach
```
2026-10-17 19:28:14 +00:00
Extra arguments are forwarded to the client, with `--server` appended to the subcommand:
```bash
opencode-attach session list --format json
```
2026-03-27 17:26:11 -04:00
## API
Once running, the server exposes an OpenAPI 3.1 spec at:
```
2026-10-17 19:28:14 +00:00
http://localhost:4096/openapi.json
2026-03-27 17:26:11 -04:00
```
2026-10-17 19:28:14 +00:00
The web UI is served at `/` and is reachable without credentials; every `/api/*` route requires basic auth.
2026-03-27 17:26:11 -04:00
Key endpoints:
| Method | Path | Description |
|--------|------|-------------|
2026-10-17 19:28:14 +00:00
| `GET` | `/api/info` | Health check and version |
| `GET` | `/api/session` | List sessions |
| `POST` | `/api/session` | Create a session |
| `POST` | `/api/session/:id/prompt` | Send a message |
| `GET` | `/api/event` | Server-sent events stream |
2026-03-27 17:26:11 -04:00
2026-10-17 19:28:14 +00:00
See the [OpenCode v2 API reference ](https://opencode.ai/v2/docs/api/ ) for the full API surface.
2026-03-27 17:26:11 -04:00
## Image details
2026-10-17 19:28:14 +00:00
- **Base image**: `node:26-trixie` (Debian)
- **Install**: `@opencode/cli` (OpenCode 2) via npm global install
2026-03-27 17:26:11 -04:00
- **User**: dedicated non-root `opencode` user
2026-04-15 12:47:27 -04:00
- **Cluster tooling**: `kubectl` (copied from official registry image)
2026-10-17 19:28:14 +00:00
- **Entrypoint**: `opencode`
2026-03-27 17:26:11 -04:00
- **Default port**: `4096`