This Compose setup runs the OpenCode 2 beta CLI (opencode2) in the Gluetun
Proton VPN network namespace. OpenCode traffic is therefore covered by
Gluetun's VPN firewall instead of relying on HTTP_PROXY settings.
OpenCode 2 is currently a beta and its official documentation does not list
Docker as a supported installation target. This setup installs the official
V2 npm package inside a Linux container and verifies that the opencode2
binary is present during the image build.
- Copy
.env.exampleto.env. - Generate a Proton VPN WireGuard configuration for a US server from the Proton account portal.
- Put the configuration's
[Interface]PrivateKeyvalue in.envasWIREGUARD_PRIVATE_KEY. - Add the provider API key needed by your OpenCode configuration to
.env. - Set a strong
OPENCODE_SERVER_PASSWORDin.env; use the same value when connecting host-side CLI clients.
The host's ~/.agents directory is mounted read-only at /root/.agents, so
OpenCode can discover skills from ~/.agents/skills.
Start the VPN and opencode container:
docker compose up -d Open the web client at http://127.0.0.1:4096. The server and web client can
access repositories beneath the mounted /repo directory. The server port is
bound to localhost only; override OPENCODE_SERVER_PORT in .env if the host
port is already in use.
Connect another CLI client to the running server:
opencode2 --server http://127.0.0.1:4096 /path/to/projectSet OPENCODE_SERVER_PASSWORD in the client environment before running that
command.
Stop the server when finished:
docker compose stop opencodeThe optional HTTP proxy is available only on the host at
http://127.0.0.1:8888 by default. OpenCode itself does not need to use this
proxy because its entire network namespace already belongs to Gluetun.
Check that the VPN is healthy:
docker compose ps
docker compose logs gluetunCheck the public address from the same network namespace as OpenCode:
docker compose run --rm --entrypoint sh opencode -lc 'curl -fsS https://ifconfig.me'The returned address should be a Proton VPN US exit address. If Gluetun is unhealthy, the OpenCode container cannot start because of the health-gated dependency.