Docker and the OpenCode image: install, run without sudo, pull and check

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.

This article is step 1 (Docker and the OpenCode image) of the manual in full.

Before you start, you need two things: Docker on your computer, and the official OpenCode image in the same version as the OpenCode you use.

Your own image in step 3 (the image) is built on top of that image. The commands are for Ubuntu 24.04.

Install Docker

Docker from the Ubuntu repository is enough.

docker-buildx is the BuildKit builder: without it every build prints DEPRECATED: The legacy builder is deprecated.

sudo apt update

sudo apt install docker.io docker-buildx

Docker without sudo

To run docker without sudo, add yourself to the docker group, then log out and in again:

sudo usermod -aG docker $USER

docker --version

Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2

Pull the OpenCode image

Pull the official OpenCode image of the version you run on the host.

It is the base of your own image in step 3 (the image):

opencode --version

opencode v2.1.4

docker pull ghcr.io/anomalyco/opencode:2.1.4

docker run --rm ghcr.io/anomalyco/opencode:2.1.4 --version

opencode v2.1.4

Check that both are there

Before you go on to step 2 (a worktree for the agent) of OpenCode in Docker on Ubuntu 24.04, check both.

The tag in the last command is the version that opencode --version printed:

docker --version

Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2

opencode --version

opencode v2.1.4

docker image inspect --format '{{.RepoTags}}' ghcr.io/anomalyco/opencode:2.1.4

[ghcr.io/anomalyco/opencode:2.1.4]

An image that is not there gives an error and exit code 1.

Tested with a tag that does not exist:

docker image inspect --format '{{.RepoTags}}' ghcr.io/anomalyco/opencode:9.9.9

Error response from daemon: No such image: ghcr.io/anomalyco/opencode:9.9.9

Then pull it as in Pull the OpenCode image.

When you update OpenCode on the host, pull the new tag and change FROM in every Dockerfile of the setup to it (page The image).

Article author: Klavdiya Kondakova