Skip to content

nezhar/opencode-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode Container

A Docker container with the OpenCode CLI pre-installed and ready to use.

This project mirrors the approach used in claude-container and devstral-container: run the CLI in an isolated environment with a persisted config directory and your local workspace mounted in /workspace.

Quick Start

Using the Helper Script (Recommended)

# Download and install
curl -o ~/.local/bin/opencode-container https://raw.githubusercontent.com/nezhar/opencode-container/main/bin/opencode-container
chmod +x ~/.local/bin/opencode-container

# Run OpenCode
opencode-container

Make sure ~/.local/bin is in your PATH, or install system-wide with sudo:

sudo curl -o /usr/local/bin/opencode-container https://raw.githubusercontent.com/nezhar/opencode-container/main/bin/opencode-container
sudo chmod +x /usr/local/bin/opencode-container

Using Docker Directly

docker run --rm -it \
  -v "$(pwd):/workspace" \
  -v "$HOME/.config/opencode-container:/config" \
  -v "$HOME/.local/share/opencode:/data" \
  -e "HOME=/config" \
  -e "OPENCODE_CONFIG_DIR=/config" \
  -e "XDG_DATA_HOME=/data" \
  nezhar/opencode-cli:latest

Helper Script Options

opencode-container --help
opencode-container --pull
opencode-container --shell
opencode-container "analyze the code"
opencode-container --proxy --proxy-provider openai --proxy-target https://api.openai.com
opencode-container --datasette --proxy-provider openai --proxy-target https://api.openai.com
opencode-container --proxy-all

Optional API Logging

Enable API logging through a reverse proxy and store requests/responses in SQLite:

opencode-container --proxy \
  --proxy-provider openai \
  --proxy-target https://api.openai.com

Logs are stored at:

~/.config/opencode-container/proxy/logs.db

To explore logs in a web UI, start Datasette:

opencode-container --datasette \
  --proxy-provider openai \
  --proxy-target https://api.openai.com

Datasette is available at http://localhost:8001.

No other host ports are published by default.

If your provider uses a different base path, override the base URL injected into OpenCode:

opencode-container --proxy \
  --proxy-provider openai \
  --proxy-target https://api.openai.com \
  --proxy-base-url http://opencode-proxy:8080/v1

Intercept All Traffic (Forward Proxy)

To capture requests from multiple providers without changing OpenCode config:

opencode-container --proxy-all

This sets HTTP_PROXY/HTTPS_PROXY for the CLI container and trusts the mitmproxy CA. If HTTPS requests fail on first run, re-run the command after the proxy generates its CA files in ~/.config/opencode-container/proxy/certs.

Configuration

Configuration is stored on the host in:

~/.config/opencode-container

Credentials are stored on the host in:

~/.local/share/opencode/auth.json

These paths are mounted into the container as /config and /data, with HOME=/config and XDG_DATA_HOME=/data.

Proxy-related environment variables:

OPENCODE_PROXY_PROVIDER
OPENCODE_PROXY_TARGET
OPENCODE_PROXY_BASE_URL
OPENCODE_PROXY_DATA
OPENCODE_PROXY_MODE
OPENCODE_PROXY_PORT
OPENCODE_DATASETTE_PORT
OPENCODE_PROXY_IMAGE
OPENCODE_DATASETTE_IMAGE

Build Locally

docker compose build

Shell Completion

mkdir -p ~/.local/share/bash-completion/completions
cp completions/opencode-container ~/.local/share/bash-completion/completions/

Related Projects

  • claude-container
  • devstral-container

About

A Docker container with the OpenCode CLI pre-installed and ready to use.

Resources

Stars

Watchers

Forks

Packages