Version: Weekly Build
Custom Workspace Base Images
The default base image for workspaces already ships with many useful tools and
libraries. However, you can create your own custom base images. One reason to
customize base images is packages that are not available through Nix but need to
be installed via apt.
The Codesphere OMS CLI provides a convenient way to start building your own custom base images.
Prerequisites:
- On your host, install Docker and the Buildx plugin (if not already installed):
sudo apt install docker.io docker-buildx - Install the OMS CLI as described at https://github.com/codesphere-cloud/oms
- Use the
extend baseimagecommand in OMS CLI, seeoms beta extend baseimage -h - This command extracts the default base image from the Codesphere installer bundle, loads it into your local Docker image cache, and generates a Dockerfile that you can extend.
- Confirm with
docker image lsthat the base image (ghcr.io/codesphere-cloud/codesphere-monorepo/workspace-agent-VERSION) is available locally. - Edit the generated Dockerfile to add your custom dependencies.
- As a best practice, place the Dockerfile into a subdirectory, e.g.
./docker. This ensures that in the followingdocker buildcommand, only the necessary files are sent to the Docker daemon. - Retrieve the base image tag from the Dockerfile, e.g.
codesphere-1-67-1-4dd9b346cc, and use the same tag for your custom image. - Build the custom image with the following command:
docker buildx build -f ./docker/custom.Dockerfile -t workspace-agent-24.04-mycorp:<TAG_TO_USE> --load ./docker - Tag and push the image to your own registry with the same tag as the original
image:
docker tag workspace-agent-24.04-mycorp:<TAG_TO_USE> <YOUR_REGISTRY_URL>/workspace-agent-24.04-mycorp:<TAG_TO_USE>docker login <YOUR_REGISTRY_URL> # if not already logged indocker push <YOUR_REGISTRY_URL>/workspace-agent-24.04-mycorp:<TAG_TO_USE>
warning
The image name can be freely chosen, but double-check that the tag of your custom image matches the original base image tag exactly. If the tags do not match, Codesphere will currently not be able to find your custom image when starting workspaces.