Can container/src itself be the Docker volume of OpenCode?
Introduction
This article is part of a larger manual,
OpenCode in Docker on Ubuntu 24.04.
The manual shows how to run OpenCode with
the --auto option inside a
Docker container.
With --auto the agent does not ask you before
each command, so the container limits what it can reach: the agent works
only in one git worktree, a separate copy of the
project.
The agent works in container/src, the docroot of
the site.
This article answers a common question: can this folder itself be the
volume of the container?
Yes, the worktree's
Yes, and it is the volume here. -v with a host
path is a bind mount: the folder itself, not a copy.
What matters is which container/src you mount:
| Source | The agent sees | Use |
|---|---|---|
| the worktree's | tracked files only | this one |
| the main checkout's | tracked files, ignored ones and your uncommitted edits | only with masks |
| a named volume | an empty folder; edits stay inside Docker | no |
Not the main checkout's
In the main checkout the ignored files are inside.
Checked on a test repo with a dummy log in
container/src/logs:
docker run --rm -v "$PWD/container/src:/work/container/src:ro" --entrypoint sh opencode-agent -c 'ls container/src/logs'
visits.log
A tmpfs mount on top of a folder hides it. This command prints nothing:
docker run --rm -v "$PWD/container/src:/work/container/src" --mount type=tmpfs,destination=/work/container/src/logs --entrypoint sh opencode-agent -c 'ls -A container/src/logs'
- Every ignored path needs its own mask. Their list comes from git status --short --ignored container/src, and a log that appears tomorrow under a new name is not masked.
- The agent edits your working tree. There is no branch to drop, and its edits mix with your uncommitted ones.
- The worktree has neither problem. That is why the launcher refuses a folder with ignored files.
Article author: Klavdiya Kondakova