From d6835d1910ff02ebee440fdfb197c45179a17ae0 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 20 Nov 2026 09:25:30 +0100 Subject: [PATCH] docs: describe a volume at /opt/containerbase Co-Authored-By: Claude Opus 5.5 --- docs/custom-base-image.md | 50 +++++++++++++++++++++++++++++++++++++++ docs/custom-root-ca.md | 2 ++ docs/linking.md | 2 ++ 3 files changed, 54 insertions(+) diff --git a/docs/custom-base-image.md b/docs/custom-base-image.md index dc71f0326f..4ab22afabc 100644 --- a/docs/custom-base-image.md +++ b/docs/custom-base-image.md @@ -193,3 +193,53 @@ RUN containerbase-cli init tool all When the rootfs isn't reset between jobs, the tool caches and configs (`.npm`, `.m2`, `.npmrc`, …) in that folder carry over to the next job. Reset the rootfs per job or clean the folder yourself. + +## Volume at `/opt/containerbase` + +You can mount a volume at `/opt/containerbase`, eg. to run a read-only root file system with a writable `/opt/containerbase`, or to keep tools between runs. +The tools you installed at image build time as root are recorded in `/var/lib/containerbase/tool.inst`, a plain text list which is part of the image, and in a copy at `/opt/containerbase/.tool.inst`. +The list is only written for BuildKit builds, as containerbase detects a build by its BuildKit mounts. +An image built with kaniko, buildah or podman has no list, so its own tools are lost on an empty volume. + +### Empty volume + +An empty volume hides the tools of the image. +The `docker-entrypoint.sh` runs `containerbase-cli init tool all`, which compares the list of the image with the copy on the volume. +When they differ, which is the case for a new volume and after an image update, it sets up the volume from the list: + +- it creates the folders, the database records, the shims in `bin` and the current versions +- the versions of the image win over the ones installed at runtime +- it installs `jq` at once, as the shell utils need it, `git` comes with the image +- it copies the list to the volume, so the next start has nothing to do +- it never removes anything: versions of an older image stay on the volume until you remove them with `uninstall-tool` or `containerbase-cli cleanup` + +All other tools are installed on their first call, see [how tools are linked](./linking.md#containerbase-cli-ensure). +The first call of each tool downloads it, so a volume needs network access and doesn't work in an air-gapped setup. +Tools which are installed again download their dependencies again, eg. npm and pip packages. +A restore by a shim doesn't fetch hex and rebar for elixir, run `mix local.hex --force` and `mix local.rebar --force` afterwards. +A tool you use by its path or by an environment variable, eg. `JAVA_HOME`, without calling its command first, is missing until its command or `install-tool` installed it. +`docker buildx` and `docker compose` go through the shims of `buildx` and `docker-compose`, so the first call installs them. +Docker commands which list the plugins, eg. `docker info` and `docker help`, run every plugin and so install buildx and compose too. + +Not part of the list, and so lost on a volume: + +- the v2 shell tools, as the shims can't install them again, install them again at runtime +- a command which a v2 shell tool takes over from an older tool at build time: the link line of the older tool stays in the list, so on a volume the command runs the older tool +- files other software put into `/usr/local/bin` or `/usr/local/lib`, as these link to `/opt/containerbase/bin` and `/opt/containerbase/lib`, use `/usr/local/sbin` or `/usr/bin` instead +- a custom Java `cacerts` copied to `/opt/containerbase/ssl/cacerts`, mount it at runtime instead, see [custom root CA certificates](./custom-root-ca.md#runtime-java-install) +- the `env.d` files of custom v2 tools + +In a multi-stage build, copy `/opt/containerbase` and `/var/lib/containerbase` from the same stage. +Copying only `/opt/containerbase` from a builder stage gives a list which differs from its `.tool.inst`, so the setup runs on every start and the current versions of the base image replace the ones of the builder. + +A custom entrypoint must run `containerbase-cli init tool all`. +The `docker-entrypoint.sh` does it when `/tmp/containerbase` is missing, or when the volume has another list than the image. + +### Copy of the image folder + +A copy of `/opt/containerbase` of the image, eg. made with `cp -a` in an init container as root or as the containerbase user, is supported too. +The copy has the list of the image, so the init has nothing to do and no tool is downloaded. + +### Disk instead of memory + +Back the volume with a disk, eg. a disk-backed `emptyDir`, not with memory: the tools need a few hundred megabytes up to some gigabytes. diff --git a/docs/custom-root-ca.md b/docs/custom-root-ca.md index 453716df4c..f8e298896e 100644 --- a/docs/custom-root-ca.md +++ b/docs/custom-root-ca.md @@ -62,6 +62,8 @@ Don't mount your certificates over `/etc/ssl/certs`, this hides the default cert For Java you need to mount your own certificate store to `/opt/containerbase/ssl/cacerts`. +A custom store which you copied to `/opt/containerbase/ssl/cacerts` at build time is lost when a [volume](./custom-base-image.md#volume-at-optcontainerbase) hides `/opt/containerbase`, mount it at runtime as shown here. + ```bash docker run --rm -it \ -v my-root-ca.crt:/my-root-ca.crt \ diff --git a/docs/linking.md b/docs/linking.md index 15261a9c3d..0bcad375f3 100644 --- a/docs/linking.md +++ b/docs/linking.md @@ -67,5 +67,7 @@ This doesn't apply to tools which can't be uninstalled, like `git`, and to the v It downloads nothing, a command whose version folder is missing is installed again on its first call. - A command without a row in the `links` database can't be restored, install the tool again. +A [volume at `/opt/containerbase`](./custom-base-image.md#volume-at-optcontainerbase) uses the same recovery: `init tool all` sets up the shims from the build-time list of the image, and each tool is installed again on its first call. + A setup with a read-only root file system keeps working: the pointers are part of the image. A call of a command whose version is missing fails there, as the containerbase folders can't be written.