Docker container for OpenCode v2 - the open source AI coding agent.
- OpenCode AI - Pinned to a specific version (
.opencode-version) for reproducible builds - Node.js - Latest from node:alpine base image, for npm-based MCP servers (
npx) - Python 3 + pip - For Python-based MCP servers (
uvx) and pip packages - uv - Fast Python package manager
- git - Version control
- ripgrep (rg) - Fast code search
- jq - Command-line JSON processor
- curl - HTTP requests
- bash - Shell scripting
- tar - Archive extraction
- Alpine Linux - Minimal base image
Minimal (ephemeral - data lost on restart):
docker run -d -p 4096:4096 -e OPENCODE_HOSTNAME=0.0.0.0 vinnyahh/opencode-box:latest
# v2 always password-protects the server; with no OPENCODE_SERVER_PASSWORD set
# it generates one and prints it at startup. Fetch it with:
docker logs <container> | grep 'server password'
⚠️ Security:OPENCODE_HOSTNAME=0.0.0.0is required for the published port to be reachable. In v2 the server is always password-protected: withOPENCODE_SERVER_PASSWORDset it uses your password; otherwise it generates one and prints it at startup. Connecting clients authenticate with the same value viaOPENCODE_PASSWORD.
With persistence:
docker run -d \
-p 4096:4096 \
-e OPENCODE_PORT=4096 \
-e OPENCODE_HOSTNAME=0.0.0.0 \
-e OPENCODE_SERVER_PASSWORD=change-me \
-e OPENCODE_CONFIG=/config/opencode.json \
-v ./config:/config \
-v ./data:/data \
-v ./projects:/projects \
vinnyahh/opencode-box:latestAccess at http://localhost:4096 and log in with the server password.
| Variable | Description | Default |
|---|---|---|
OPENCODE_PORT |
Server port | 4096 |
OPENCODE_HOSTNAME |
Server hostname | 127.0.0.1 |
OPENCODE_CONFIG |
Path to config file | auto-detect |
OPENCODE_SERVER_PASSWORD |
Server password (web UI login, pairing, client auth) | auto-generated |
OPENCODE_PASSWORD |
Also read server-side as the password; how connecting clients pass the password | - |
DEBUG=true |
Entrypoint debug output (versions, PATH, config and symlink status) | - |
| Path | Description |
|---|---|
/config |
OpenCode config, agents, commands |
/data |
Sessions, auth, logs |
/projects |
Your project files |
Expected structure:
config/
├── opencode.json # Main config file
├── agents/ # Custom agents (markdown) — preferred v2 location
├── commands/ # Custom commands
├── plugins/ # Custom plugins (v2 plugins use the @opencode/plugin API)
├── skills/ # Custom skills
├── themes/ # Custom themes
└── tools/ # Custom tools
data/
├── opencode.db # All sessions & messages (SQLite)
├── auth.json # API credentials (auto-generated)
├── mcp-auth.json # MCP OAuth tokens (auto-generated)
├── snapshot/ # Session checkpoints
└── log/ # Log files
projects/
└── (your code) # Your project files
Legacy v1 directories are still discovered by v2: mode/ and modes/ (entries load as
primary agents), agent/ alongside agents/, command/ alongside commands/,
plugin/ alongside plugins/, and skill/ alongside skills/. Prefer the singular
v2 locations above for anything new.
This container supports running MCP (Model Context Protocol) servers:
| MCP Server Type | Runtime | Example Command |
|---|---|---|
| Node.js packages | npx |
npx -y @modelcontextprotocol/server-github |
| Python packages | uvx |
uvx mcp-server-sqlite |
| Remote servers | HTTP | URL in config |
v2 transparently normalizes legacy v1-style
mcpblocks. The native v2 shape groups servers undermcp.serversand usesdisabledinstead ofenabled. Both load fine — the example config intentionally keeps the v1 shape.
The container can be paired with a browser for frontend testing, visual verification, and DevTools-based workflows. Two approaches:
Run Chrome on your host machine with remote debugging enabled, then configure the MCP to connect through Docker's host gateway:
# On your host machine (macOS/Linux):
chrome --remote-debugging-port=9222 --no-sandbox
# Point the MCP at the host's Chrome from inside the container:
# MCP server URL: http://host.docker.internal:9222/jsonNo changes to the container — Chrome runs on the host. All DevTools tools (snapshot, click, fill, evaluate, performance, etc.) work over this connection.
For CI-style environments or when you don't want to depend on a host browser, add Playwright or Puppeteer to your setup — they bundle their own Chromium:
# In your Dockerfile or at runtime:
npx playwright install chromiumThis approach works out-of-the-box in the container but uses Playwright/Puppeteer APIs directly rather than the Chrome DevTools MCP protocol.
Alpine/musl caveat: Playwright/Puppeteer's downloaded browsers are glibc (Ubuntu) builds and fail on this musl image with
spawn ENOENT/ "required file not found". Use Alpine's musl-native Chromium instead:apk add chromiumand point Playwright (or the browser MCP) at--executable-path /usr/bin/chromium.
The docker-entrypoint.sh handles startup automatically:
- Config auto-detection — Looks for
/config/opencode.jsoncfirst, then/config/opencode.json. Override with theOPENCODE_CONFIGenvironment variable. - Directory linking — Symlinks
/config→~/.config/opencodeand/data→~/.local/share/opencode, but only when the default paths are free. Mounting state directly at the defaults (e.g.-v ~/.config/opencode:/root/.config/opencode) works equally well and skips the symlinks entirely. - Debug mode — Set
DEBUG=trueto print version info, PATH, config and symlink status on startup.
The container has a built-in HEALTHCHECK that requests / every 30s via 127.0.0.1 — v2 binds IPv4 only, so localhost would first resolve to ::1 and report connection refused. Works with Docker's health status and orchestration tools.
MIT