The repository's Dockerfile builds Oscar as one static binary (musl) and
runs it as an unprivileged user (oscar, uid 10001) in a small Alpine
image. Oscar's home (keys, sessions, memory, skills, settings) is a volume,
so it survives the container; the project you work on is mounted at
/work.
This is a different thing from sandbox = "docker" (see
approvals-and-sandbox.md), where Oscar runs on your machine and only its
commands go into a container.
Build
docker build -t oscar-agent .Docker from your distribution works (on Debian and Ubuntu: sudo apt install docker.io docker-buildx docker-compose-v2; without docker-buildx,
docker build falls back to the deprecated legacy builder and says so).
The build compiles everything from source and takes a while: about 20
minutes on five cores.
The build stage compiles on rust:1-alpine with the toolchain
rust-toolchain.toml names; the final image has the binary, bash, git,
curl, certificates and the usual command-line tools. Add your project's
own toolchain (compilers, package managers) in a Dockerfile of your own
that starts FROM oscar-agent.
First run: setup
docker volume create oscar-home
docker run -it --rm -v oscar-home:/home/oscar/.oscar oscar-agent setuposcar setup stores the provider's key in credentials.env inside the
volume (mode 0600). You can also pass keys as environment variables
(-e OPENROUTER_API_KEY=…); never bake them into an image.
Chat in a project
docker run -it --rm \
-v oscar-home:/home/oscar/.oscar \
-v "$PWD":/work \
oscar-agentThe default command is oscar chat. Every other command works the same
way: docker run … oscar-agent run "summarise the open issues",
… oscar-agent doctor, … oscar-agent sessions.
Files Oscar writes in /work belong to uid 10001. To keep your own user
as the owner, run the container as you: --user "$(id -u):$(id -g)" (the
home volume must then be writable by that user, e.g. created with
docker run --rm -v oscar-home:/h alpine chown -R "$(id -u):$(id -g)" /h).
The chat gateways
docker run -d --name oscar-gateway --restart unless-stopped \
-v oscar-home:/home/oscar/.oscar \
-v /srv/projects:/work \
oscar-agent gateway serveConfigure the platforms first (docker run -it --rm -v oscar-home:/home/oscar/.oscar oscar-agent setup gateways). docker stop
drains like oscar gateway stop: running turns get drain_timeout to
finish, so give it the time (docker stop -t 90). docker logs shows what
oscar logs gateway would; inside the volume the logs are kept too.
Docker Compose
The repository's compose.yaml runs the chat gateways as a service, and on
request the API server beside them, from the same
image:
docker compose build
docker compose run --rm gateway setup # once: provider, keys, chat platforms
docker compose up -d # the chat gateways
docker compose --profile api up -d # also the API, on 127.0.0.1:8642
docker compose ps # state and health
docker compose logs -f gateway
docker compose stop # drains running turns firstKeys. The compose file holds no secrets. Put keys in oscar.env next to
it, one NAME=value per line (chmod 600 oscar.env); git and the image
build ignore that file. Or let setup write them to credentials.env in
the home volume. A key that is a secret-manager reference
(op://, bw://, bws://, cmd:) needs its program in the image, which
the stock image does not have.
What runs how.
- Both services run as the image's user (uid 10001), never root, with a
read-only root filesystem, every capability dropped and
no-new-privileges. They can write to the home volume (oscar-home, at/home/oscar/.oscar, the same volume thedocker runexamples use), the workspace (oscar-work, at/work) and two small in-memory folders:/tmpand the user'sHOME(for what commands keep there, such asgit config; emptied when the container restarts). - To work on a project of yours, replace the
oscar-workline with a bind mount (- /srv/projects/site:/work), writable by uid 10001 (or setuser:to your own ids, as in thedocker runnotes above). init: truereaps the processes commands leave behind and passes signals on;restart: unless-stoppedbrings a service back after a crash or a reboot.
Stopping and draining. docker compose stop (or down) sends the
gateway the same signal as oscar gateway stop: no new turns, running ones
get drain_timeout (60 seconds by default) to finish. stop_grace_period
is 90 seconds; raise it with drain_timeout.
Health. The gateway's check is oscar -q doctor every five minutes: it
fails when the configuration is broken (a provider without its model or
key) and makes no network calls (the connectivity probe needs --probe).
The API's check is GET /health every 30 seconds (no key needed).
docker compose ps shows healthy or unhealthy; docker inspect --format '{{json .State.Health}}' oscar-gateway-1 shows the last outputs.
The API service (--profile api) listens on 0.0.0.0:8642 inside the
container, which the server allows only with OSCAR_API_SERVER_KEY (at
least 16 characters, in oscar.env or credentials.env) and --public;
without the key it refuses to start. The port is published on
127.0.0.1 only: put a TLS proxy in front before opening it to other
machines. Both services share the home volume, so API sessions and chat
sessions live in one store.
Upgrading. Pull or check out the newer version, then docker compose build and docker compose up -d: the containers are replaced, the volumes
stay. Run docker compose run --rm gateway doctor afterwards to see the
new version's checks.
A model server on the same machine
Inside the container 127.0.0.1 is the container itself, so a model
server on the machine (Ollama, vLLM, llama.cpp, all listening on
127.0.0.1 by default) is not reached at that address. On Linux the
simplest way is --network host (network_mode: host in compose.yaml):
the container shares the machine's network and
CUSTOM_BASE_URL=http://127.0.0.1:11434/v1 works as on the machine.
Otherwise make the server listen where the container can reach it (for
Ollama OLLAMA_HOST=0.0.0.0, kept off the internet by a firewall) and give
the container --add-host=host.docker.internal:host-gateway with
CUSTOM_BASE_URL=http://host.docker.internal:11434/v1.
Where commands run
Inside the container Oscar works in host mode by default: the container is
its machine, so commands reach only what the container has (the mounted
/work and the network). The workspace sandbox (sandbox = "workspace")
needs user namespaces, which most container runtimes do not allow; the
Docker backend needs a Docker daemon, which the image does not include.
Approvals work as everywhere: dangerous commands still need a human, and
a gateway with nobody to ask refuses them.
Updating
Rebuild the image from a newer checkout and start a new container with the
same volume. oscar update inside a container replaces only the
container's copy of the binary and is lost with it; rebuild instead.
Notes
- Nothing in the image needs root at run time; the image never runs as root.
- The image has no secrets.
credentials.envlives in the volume; a backup of the volume (oscar backup) leaves secrets out unless asked. - Several profiles: mount one volume per profile, or use
-p NAMEwith the profiles inside one volume (see operations.md).