-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(docker): Run server in Docker with auth sync + local build #2359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,50 @@ | |||
| name: Publish Docker Image | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an attempt to try to automate some of the infrastructure, automatically publishing new opencode docker images to docker hub whenever new opencode releases are released. The image would have the latest opencode server pre-built.
packages/opencode/src/cli/cmd/tui.ts
Outdated
| if (!docker) { | ||
| UI.error("docker not found, starting server locally") | ||
| return Server.listen({ port: args.port, hostname: args.hostname }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For discussion if we want to allow this fallback. If I am depending on opencode to be isolated, I might miss that it failed and not notice if it just quietly falls back
| RUN sed -i 's/"@opencode-ai\/sdk": "workspace:\*"/"@opencode-ai\/sdk": "latest"/g' package.json && \ | ||
| sed -i 's/"@opencode-ai\/plugin": "workspace:\*"/"@opencode-ai\/plugin": "latest"/g' package.json && \ | ||
| node -e 'const fs=require("fs"); const root=JSON.parse(fs.readFileSync("/tmp/root.package.json","utf8")); const pkg=JSON.parse(fs.readFileSync("package.json","utf8")); const cat=(root.workspaces&&root.workspaces.catalog)||{}; if(pkg.dependencies){for(const k of Object.keys(pkg.dependencies)) if(pkg.dependencies[k]==="catalog:") pkg.dependencies[k]=cat[k]||pkg.dependencies[k];} if(pkg.devDependencies){for(const k of Object.keys(pkg.devDependencies)) if(pkg.devDependencies[k]==="catalog:") pkg.devDependencies[k]=cat[k]||pkg.devDependencies[k];} fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2));' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a hack around not putting the entire monorepo into the docker context, open to other suggestions
…local build flags, script/docker-build, and publish-docker workflow
…sure golang-go/node/jq; verified build
…o server for seamless creds
… for TUI when enabled; update TUI to honor config
5321b58 to
a8dd115
Compare
…r not ready; prevent TUI crash/connection refused
f16de3d to
cc0d460
Compare
772b621 to
eb855e1
Compare
|
Why only run the Opencode server in a container? Why would one trust the TUI to run on your host? One of the strengths of terminal interfaces is that you can run the whole thing inside a container without any issues (compared to GUI that require X11 support on host). With this approach the issue of how to define projects and link them with sessions will reappear? In the container all projects will be mounted at Eventually one would like to give the Opencode server access to some tools, install binaries, and add custom mountpoints, so docs should contain instructions for this. For example to keep the host system clean one might want to give Opencode container access to a "firewalled Docker socket" ( |
f1dc981 to
3e15a39
Compare
f8ee907 to
6a9856d
Compare
Adds an optional Docker-backed server mode for the TUI and headless server to isolate the runtime environment without sacrificing TUI performance.
The workspace isolation is especially useful in enterprise environments. Local machines can oftentimes contain lots of tools and credentials that are quite destructive. Allowing an AI agent to run on your local machine with the same basic access to your entire system as you have can be dangerous.
This instead isolates the opencode server to run inside a docker container with only the current working directory mounted inside as a volume. This way, the agent can only modify those files, and has no other access to the host system. Since only the server is running in the container and not the TUI itself, the performance penalty should be relatively minimal.
Why
What
--dockerflag to start the server in Docker, mounting$PWDto/workspaceand mapping a host port to container8080.opencodeai/opencode:server; support--docker-image.--dockerfile,--docker-context,--docker-buildfor building a local image; addedscript/docker-buildanddocker:buildscript.PUT /auth/:id) and inject only provider-defined env vars (from models.dev) into the container (e.g.OPENAI_API_KEY,ANTHROPIC_API_KEY). No $HOME/XDG dirs are mounted.oven/bun; installs minimal tools (git,curl,unzip,tar,nodejs,npm,golang) and runsbun run /app/src/index.ts serve --hostname 0.0.0.0 --port 8080.opencodeai/opencode:serveron release (multi-arch).server.docker(bool) andserver.imageso plainopencodecan auto-use Docker server mode by default.Usage
opencode --docker(uses Hub image) oropencode --docker --docker-image opencode:localafter a local buildopencode serve --docker --port 8080bun run docker:build(tags bothopencodeai/opencode:serverandopencode:local)Notes