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:

SourceThe agent seesUse
the worktree'stracked files onlythis one
the main checkout'stracked files, ignored ones and your uncommitted editsonly with masks
a named volumean empty folder; edits stay inside Dockerno

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'

Article author: Klavdiya Kondakova