One of our clients, a company that builds edge vision devices on an NVIDIA Jetson module, asked us to keep its Yocto image small and stable while its application teams shipped new analytics every few weeks. The answer was to split the two. The BSP team owns the base system, kernel, drivers and container engine, and every application runs as a container. Devices receive new application versions from the company registry, pulled by an update client that is itself a container and drives the engine through its socket.
The Yocto build can do more than build the host. It can compile the applications into OCI images, install them in the root file system so that a device leaves the factory with its applications, and publish the same images to the registry for later updates. This article does it with Docker, Podman and containerd on the qemuarm64 machine of Yocto Wrynose with the meta-virtualization layer, and every output comes from QEMU. Our introduction to Linux containers explains the namespaces, runtimes and engines the article relies on.
Contents
Checking the Kernel of the BSP
Containers need a set of kernel options, namespaces, cgroups, overlayfs, veth, bridge and netfilter among them, and a BSP kernel configured for a product without containers usually lacks some. Docker ships a script that checks them, check-config.sh, installed by the docker-moby-contrib package of meta-virtualization. It reads /proc/config.gz and applies to every engine. On the linux-yocto kernel of the hosts built below:
root@qemuarm64:~# /usr/share/docker/check-config.sh info: reading kernel config from /proc/config.gz ... Generally Necessary: - cgroup hierarchy: cgroupv2 Controllers: - cpu: available - cpuset: available - io: available - memory: available - pids: available - CONFIG_NAMESPACES: enabled [...] - CONFIG_IP6_NF_TARGET_MASQUERADE: missing - CONFIG_NETFILTER_XT_MATCH_ADDRTYPE: enabled (as module) - CONFIG_NETFILTER_XT_MATCH_CONNTRACK: enabled (as module) - CONFIG_NETFILTER_XT_MATCH_IPVS: missing [...] Optional Features: - CONFIG_USER_NS: enabled - CONFIG_SECCOMP: enabled - CONFIG_SECCOMP_FILTER: enabled /usr/share/docker/check-config.sh: line 258: syntax error near unexpected token `}'
The kernel has everything the script requires except two netfilter options, the IPv6 masquerade target and the IPVS match, which a BSP kernel adds with a configuration fragment if its containers need them. The patch meta-virtualization applies to the script breaks it after the optional features, once the required checks are all printed.
Building the Container Host with Yocto
The engines, their runtimes and their configuration come from the meta-virtualization layer, which depends on four layers of meta-openembedded:
$ bitbake-layers add-layer ../layers/meta-openembedded/meta-oe $ bitbake-layers add-layer ../layers/meta-openembedded/meta-python $ bitbake-layers add-layer ../layers/meta-openembedded/meta-networking $ bitbake-layers add-layer ../layers/meta-openembedded/meta-filesystems $ bitbake-layers add-layer ../layers/meta-virtualization
meta-virtualization ships configuration fragments in its conf/distro/include directory. We include them from conf/local.conf for brevity, where a product puts them in the distro configuration of its own layer. The hosts are configured with:
# conf/local.conf
BUILD_PROFILE ?= "docker"
require conf/distro/include/meta-virt-host.conf
require conf/distro/include/container-host-${BUILD_PROFILE}.conf
BBMULTICONFIG = "vruntime-aarch64 container-aarch64"
INIT_MANAGER = "systemd"
meta-virt-host.conf is common to every container host. It enables the distro features a host needs, virtualization, systemd, seccomp for system call filtering, and vcontainer, which lets the build install container images into the host image.
BUILD_PROFILE is a convention of the meta-virtualization documentation that the layer never reads. It lets one word switch the engine, and the fragment it selects sets CONTAINER_PROFILE, which makes layer.conf include meta-virt-container-${CONTAINER_PROFILE}.inc.
The included file selects the engine, OCI runtime and networking through the VIRTUAL-RUNTIME_container_* variables. The Docker profile sets docker-moby and virtual-runc, with no networking package because Docker brings its own. The Podman profile sets podman, crun and netavark, and the containerd profile sets containerd, crun and cni. bitbake-getvar shows each value and the file that assigned it.
BBMULTICONFIG adds BitBake configurations that run alongside the main build. vruntime builds the small virtual machine that installs container images at build time, and container builds container images for another architecture. meta-virt-host.conf declares both for aarch64 and x86-64, and an arm64 target keeps the aarch64 ones.
Writing the Host Image Recipe
meta-virtualization provides container-image-host as a reference image. For a product, we need our own image recipe while retaining the configuration that makes the container host work. Our vision-host-image.bb, stored in the product layer, supports all three engines:
SUMMARY = "Container host image of the vision devices"
LICENSE = "MIT"
inherit core-image features_check container-cross-install
REQUIRED_DISTRO_FEATURES = "virtualization systemd seccomp"
# Engine packages for each profile of meta-virtualization
ENGINE_PACKAGES[docker] = "packagegroup-docker"
ENGINE_PACKAGES[podman] = "packagegroup-podman packagegroup-netavark"
ENGINE_PACKAGES[containerd] = "packagegroup-containerd"
IMAGE_INSTALL = " \
packagegroup-core-boot \
kernel-modules \
packagegroup-oci \
container-host-config \
${@d.getVarFlag('ENGINE_PACKAGES', d.getVar('CONTAINER_PROFILE'))} \
"
# Packages of the container-registry image feature
FEATURE_PACKAGES_container-registry = "${@bb.utils.contains('CONTAINER_PROFILE', 'docker', 'docker-registry-config', 'container-oci-registry-config', d)}"
IMAGE_ROOTFS_EXTRA_SPACE = "2000000"
The recipe inherits container-cross-install, which installs container images into the host rootfs during the build. Without this class, setting BUNDLED_CONTAINERS has no effect on the image. We use it later to install the application before the device boots. features_check checks REQUIRED_DISTRO_FEATURES and stops the build if virtualization, systemd or seccomp is missing.
The package list depends on CONTAINER_PROFILE. Variable flags keep the three lists in one recipe, and d.getVarFlag() picks the one of the current host. packagegroup-oci installs the runtime of the profile, and the engine packagegroup adds Docker, Podman with Netavark, or containerd with its CNI plugins, nerdctl and tini. A product with a single engine lists its packages directly.
container-host-config installs storage.conf, registries.conf and policy.json under /etc/containers. Podman and skopeo use these files for storage, registry access and image trust policies. In this configuration, policy.json accepts images without requiring signatures. A product that requires signed images must replace that policy.
meta-virtualization assigns the packages of the container-registry image feature only in its reference container-image-host, so our recipe sets them, docker-registry-config for Docker and container-oci-registry-config for Podman and containerd. IMAGE_ROOTFS_EXTRA_SPACE, in KiB, leaves about 2 GB in the rootfs, where the engines store their images.
Checking the Built Images
The image manifest records the packages actually installed, along with their architectures and versions. BitBake writes it beside the image in tmp/deploy/images/qemuarm64. We checked the container packages in the manifests of all three hosts:
$ grep -E "^(docker-moby|containerd|runc|crun|podman|conmon|netavark|cni|nerdctl) " \
tmp/deploy/images/qemuarm64/vision-host-image-qemuarm64.rootfs.manifest
# docker
containerd cortexa57 2.2.10+git0+991ca6a8ca
docker-moby cortexa57 v29.3.0+git1da6517e1a4381297e56862f6f373f265c28d1020+1da6517e1a
runc cortexa57 1.5.0+rc.1+git0+e1c1378fc9
# podman
conmon cortexa57 2.2.1+git0+86e810678d
crun cortexa57 1.26.0+git0+393509db56_6f7b71c2d2
netavark cortexa57 1.17.2
podman cortexa57 5.8.3+dev
# containerd
cni cortexa57 1.3.0+git0+7c27007699_6d8f05b82e
containerd cortexa57 2.2.10+git0+991ca6a8ca
crun cortexa57 1.26.0+git0+393509db56_6f7b71c2d2
nerdctl cortexa57 v2.2.1
Docker also installs containerd because dockerd delegates container execution to it. The resulting rootfs contains 410 MB of files for Docker, 363 MB for containerd and 240 MB for Podman, including the bundled application images.
Booting the Hosts in QEMU
All device-side outputs in this article were collected from these images running under QEMU. For testing, we also enabled passwordless root login:
EXTRA_IMAGE_FEATURES:append = " allow-empty-password empty-root-password allow-root-login"
This setting is only for the test environment. OE-core provides runqemu, which starts QEMU using the machine configuration and build artifacts produced by BitBake, and the QEMU that the build compiled:
$ runqemu qemuarm64 vision-host-image nographic slirp snapshot
nographic connects the guest console to the terminal. slirp enables QEMU user-mode networking, where the guest can reach the build machine at 10.0.2.2. We use that address later for the container registry.
runqemu boots the compressed rootfs only in snapshot mode, on a temporary copy. For tests that keep their changes, we start QEMU directly on a decompressed copy, with the options runqemu uses:
$ zstd -d vision-host-image-qemuarm64.rootfs.ext4.zst -o host.ext4
$ qemu-system-aarch64 -machine virt -cpu cortex-a57 -smp 4 -m 2048 -nographic \
-kernel Image -append "root=/dev/vda rw console=ttyAMA0" \
-drive id=disk0,file=host.ext4,if=none,format=raw -device virtio-blk-pci,drive=disk0 \
-netdev user,id=net0 -device virtio-net-pci,netdev=net0
Adding ,restrict=on to -netdev user,id=net0 cuts the guest off from the build machine and external networks, which we use to show that the bundled application needs no registry.
Checking the Engine on Each Host
Each host starts its engine at boot with the components its profile selected. On the Docker host:
root@qemuarm64:~# systemctl is-active docker containerd active active root@qemuarm64:~# docker info 2>/dev/null | grep -E "Server Version|Storage Driver|Cgroup Driver|Cgroup Version|Default Runtime|Docker Root Dir" Server Version: v29.3.0 Storage Driver: overlay2 Cgroup Driver: systemd Cgroup Version: 2 Default Runtime: runc Docker Root Dir: /var/lib/docker
dockerd runs with containerd beside it, runc as its runtime, the overlay2 storage driver and the systemd cgroup driver on cgroup v2. Podman runs without a daemon, and podman.socket only serves its Docker-compatible API, and systemd starts the service behind it on the first connection:
root@qemuarm64:~# systemctl is-active podman.socket; podman version --format {{.Client.Version}}
active
5.8.3-dev
root@qemuarm64:~# podman info --format "runtime {{.Host.OCIRuntime.Name}}|network {{.Host.NetworkBackend}}|storage {{.Store.GraphDriverName}} {{.Store.GraphRoot}}|cgroups {{.Host.CgroupManager}} {{.Host.CgroupsVersion}}" | tr "|" "\n"
runtime crun
network netavark
storage vfs /var/lib/containers/storage
cgroups systemd v2
tr puts each field of the --format template on its own line. Podman runs crun with Netavark, and stores its images with the vfs driver that storage.conf selects, which copies image layers instead of sharing them and uses more storage than overlayfs. On the containerd host, ctr and nerdctl are two clients of the same daemon:
root@qemuarm64:~# ctr version Client: Version: v2.2.10.m Revision: 991ca6a8ca58b47346a42093210099e090bc6c1f.m Go version: go1.26.10 Server: Version: v2.2.10.m Revision: 991ca6a8ca58b47346a42093210099e090bc6c1f.m UUID: eabfeb30-1273-4eb8-94ce-76f0c34242e7 root@qemuarm64:~# nerdctl info 2>/dev/null | grep -E "Server Version|Storage Driver|Cgroup Driver|Cgroup Version" Server Version: v2.2.10.m Storage Driver: overlayfs Cgroup Driver: systemd Cgroup Version: 2
The .m suffix is how the Makefile of containerd marks a Git tree with local changes, here the two patches of the recipe. containerd uses its overlayfs snapshotter and, like the two other engines, the systemd cgroup driver on cgroup v2.
Building the Application Image
The application is an ordinary recipe. Ours stands in for the vision service, a C program that counts frames every FRAME_INTERVAL seconds for the camera named on its command line and reports the count on TCP port 8080:
SUMMARY = "Stand-in for a vision service: prints its version and a frame count"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://frame-counter.c"
S = "${UNPACKDIR}"
do_compile() {
echo "#define APP_VERSION \"${PV}\"" > version.h
${CC} ${CFLAGS} ${LDFLAGS} -include version.h frame-counter.c -o frame-counter
}
do_install() {
install -D -m 0755 frame-counter ${D}${bindir}/frame-counter
}
The recipe filename sets PV to 1.0.0. During compilation, we write that version into version.h, then include it with the compiler’s -include option. The installed binary is /usr/bin/frame-counter.
The application recipe produces a package. A separate image recipe, frame-counter-image.bb, builds a minimal rootfs containing the application and packages it in OCI format:
SUMMARY = "OCI image of the frame-counter application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
inherit image image-oci
IMAGE_FSTYPES = "container oci"
IMAGE_FEATURES = ""
IMAGE_LINGUAS = ""
NO_RECOMMENDATIONS = "1"
IMAGE_CONTAINER_NO_DUMMY = "1"
IMAGE_INSTALL = "base-files base-passwd netbase busybox frame-counter"
PV = "1.0.0"
OCI_IMAGE_ENTRYPOINT = "/usr/bin/frame-counter"
OCI_IMAGE_CMD = "camera0"
OCI_IMAGE_ENV_VARS = "FRAME_INTERVAL=5"
OCI_IMAGE_PORTS = "8080/tcp"
OCI_IMAGE_RUNTIME_UID = "1000"
OCI_IMAGE_WORKINGDIR = "/"
OCI_IMAGE_LABELS = "com.example.component=vision"
IMAGE_FSTYPES requests the container format of OE-core, a rootfs archive without a kernel, and the oci format of the image-oci class of meta-virtualization, which packs that rootfs into an OCI image with umoci. The image-container class skips any image recipe unless the kernel provider is linux-dummy, and IMAGE_CONTAINER_NO_DUMMY = "1" lifts that check.
IMAGE_INSTALL limits the rootfs to the application, BusyBox and the basic files needed by a Linux user space. NO_RECOMMENDATIONS prevents recommended packages from being installed automatically.
The OCI_IMAGE_* variables set /usr/bin/frame-counter as the entry point, camera0 as its default argument, FRAME_INTERVAL=5 in its environment and port 8080 recorded in the image.
The remaining variables set the working directory, the labels and the runtime user. A numeric UID needs no /etc/passwd entry in the image. The PV of the image, 1.0.0 like the application, becomes its tag in the registry.
bitbake frame-counter-image writes the OCI layout to tmp/deploy/images/qemuarm64 as the directory frame-counter-image-latest-oci and as the single file frame-counter-image-latest-oci.tar.
After booting the Docker host with the image installed, we can inspect the configuration generated by the recipe:
root@qemuarm64:~# docker image inspect --format "User={{.Config.User}} Entrypoint={{.Config.Entrypoint}} Cmd={{.Config.Cmd}} Env={{.Config.Env}}" frame-counter-image:latest
User=1000 Entrypoint=[/usr/bin/frame-counter] Cmd=[camera0] Env=[FRAME_INTERVAL=5]
docker run can override each of these values without rebuilding the image.
Installing the Image at Build Time
A device should leave the factory with its applications already installed, without needing access to a registry on its first boot. The container-cross-install class of meta-virtualization handles this for Docker and Podman. The images are listed in BUNDLED_CONTAINERS, with one space-separated entry per image:
BUNDLED_CONTAINERS = "frame-counter-image:docker:always"
Each entry specifies the image recipe, the container storage backend (docker or podman), and an optional restart policy. Docker stores its images under /var/lib/docker, while Podman uses /var/lib/containers in this configuration.
Importing an arm64 image means running the engine, which the x86-64 build machine cannot do natively, so the class boots a small aarch64 virtual machine from the vruntime-aarch64 multiconfig, imports the images there and copies the resulting storage into the root file system.
The device can then start its applications without a network connection or registry. On the Docker host, booted in QEMU with network access disabled:
root@qemuarm64:~# systemctl is-active docker container-frame-counter-image active active root@qemuarm64:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f68b9814de3a frame-counter-image:latest "/usr/bin/frame-coun…" 55 seconds ago Up 55 seconds 8080/tcp frame-counter-image root@qemuarm64:~# docker logs frame-counter-image | tail -2 frame-counter 1.0.0: camera0 frame 8 frame-counter 1.0.0: camera0 frame 9
The Podman host, booted the same way, runs the same container:
root@qemuarm64:~# systemctl is-active container-frame-counter-image active root@qemuarm64:~# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9fafc1ccb18a docker.io/library/frame-counter-image:latest camera0 About a minute ago Up About a minute 8080/tcp frame-counter-image root@qemuarm64:~# podman logs frame-counter-image | tail -2 frame-counter 1.0.0: camera0 frame 11 frame-counter 1.0.0: camera0 frame 12
Podman shows the image under its fully qualified name, docker.io/library/frame-counter-image:latest, the name an updated image must take.
The optional third field of BUNDLED_CONTAINERS also controls the service generated to start the container at boot.
Docker: a Generated systemd Service
On the Docker host, container-cross-install installs a systemd unit. Its contents can be inspected with systemctl cat:
root@qemuarm64:~# systemctl cat container-frame-counter-image # /usr/lib/systemd/system/container-frame-counter-image.service [Unit] Description=Docker Container frame-counter-image:latest After=docker.service Requires=docker.service [Service] Type=simple Restart=always RestartSec=5s TimeoutStartSec=0 ExecStartPre=-/usr/bin/docker rm -f frame-counter-image ExecStart=/usr/bin/docker run --rm --name frame-counter-image frame-counter-image:latest ExecStop=/usr/bin/docker stop frame-counter-image [Install] WantedBy=multi-user.target
The unit removes any container left with the same name, and runs the Docker client in the foreground so that systemd follows the application and restarts it.
Podman: a Generated Quadlet
For Podman, the class generates a Quadlet file instead of a regular systemd unit. The Podman systemd generator converts it into a service at boot. The resulting unit is visible through the same command:
root@qemuarm64:~# systemctl cat container-frame-counter-image # /run/systemd/generator/container-frame-counter-image.service # Automatically generated by /usr/lib/systemd/system-generators/podman-system-generator # # Quadlet container file for frame-counter-image:latest # Generated by container-cross-install [Unit] [...] SourcePath=/etc/containers/systemd/container-frame-counter-image.container [...] [Service] Restart=always [...] ExecStart=/usr/bin/podman run --name frame-counter-image --replace --rm --cgroups=split --sdnotify=conmon -d frame-counter-image:latest
The generator reads the .container file in /etc/containers/systemd, and --replace with --rm creates the container again at each start.
The Restart Policy
Both engines use the restart policy supplied in BUNDLED_CONTAINERS, but that value must be valid for systemd. The examples shipped with meta-virtualization use autostart, which the class converts to Restart=unless-stopped. Although unless-stopped is a valid Docker restart policy, systemd does not recognize it. It logs Failed to parse Restart=unless-stopped, ignoring and falls back to Restart=no, so a crashed application stays stopped. Using always, or on-failure, avoids this problem.
We tested the generated services by killing the application process with SIGKILL, because the application is PID 1 inside its container and ignores SIGTERM, as explained in PID 1 and Signals.
root@qemuarm64:~# kill -9 $(pidof frame-counter); sleep 20 root@qemuarm64:~# systemctl show -p NRestarts container-frame-counter-image NRestarts=1
The Podman host gives the same result, with a new container ID, since its unit runs the container with --rm.
A Recipe and a Service for containerd
container-cross-install supports only Docker and Podman as storage backends, so it cannot preload images into containerd through BUNDLED_CONTAINERS. The same applies to any other engine, such as the containerd embedded in K3s.
For the containerd host, we instead install the OCI archive into the root file system and import it into containerd when the device starts. A small recipe, frame-counter-ctr_1.0.bb, installs both the archive and a systemd service:
SUMMARY = "frame-counter OCI archive and the systemd service that runs it with containerd"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://frame-counter-ctr.service"
S = "${UNPACKDIR}"
inherit systemd
SYSTEMD_SERVICE:${PN} = "frame-counter-ctr.service"
do_install[depends] += "frame-counter-image:do_image_complete"
do_install() {
install -D -m 0644 ${DEPLOY_DIR_IMAGE}/frame-counter-image-latest-oci.tar ${D}${datadir}/oci/frame-counter-image.tar
install -D -m 0644 ${S}/frame-counter-ctr.service ${D}${systemd_system_unitdir}/frame-counter-ctr.service
}
FILES:${PN} += "${datadir}/oci"
RDEPENDS:${PN} = "containerd"
The do_install[depends] dependency ensures that the OCI image has been built before the recipe copies its archive. The systemd class handles installation and enablement of the service.
The package is added to the containerd host with:
IMAGE_INSTALL:append:pn-vision-host-image = " frame-counter-ctr"
The :pn-vision-host-image override restricts the assignment to that image recipe, keeping the package out of the other images built by the project, including those used by the multiconfigs.
The service imports the factory image if necessary and starts the application using ctr, the low-level client included with containerd:
[Unit] Description=frame-counter container (containerd) After=containerd.service Requires=containerd.service [Service] ExecStartPre=/bin/sh -c "ctr images ls -q | grep -qx localhost/frame-counter-image:latest || ctr images import --base-name localhost/frame-counter-image /usr/share/oci/frame-counter-image.tar" ExecStartPre=-/usr/bin/ctr task rm -f frame-counter ExecStartPre=-/usr/bin/ctr containers rm frame-counter ExecStart=/usr/bin/ctr run --rm --net-host localhost/frame-counter-image:latest frame-counter ExecStop=/usr/bin/ctr task kill --signal SIGTERM frame-counter Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
The first ExecStartPre imports the archive installed in /usr/share/oci only if localhost/frame-counter-image:latest does not exist yet, so the factory image never replaces a newer one pulled from the registry. The next two remove a task or container left by a previous run. As our introduction to Linux containers explains, a containerd shim keeps a container running after its ctr client exits, and a new ctr run with the same ID would fail. --net-host shares the network of the host, because ctr, unlike nerdctl, sets up no CNI network.
With the containerd host booted in QEMU and network access disabled:
root@qemuarm64:~# systemctl is-active containerd frame-counter-ctr active active root@qemuarm64:~# ctr images ls REF TYPE DIGEST SIZE PLATFORMS LABELS localhost/frame-counter-image:latest application/vnd.oci.image.manifest.v1+json sha256:8b1492c61cd4d9b6cfba1df78b12dfda3dc433efbcfcddf91f6f2bcab2df2b7c 2.5 MiB linux/arm64 - root@qemuarm64:~# ctr task ls TASK PID STATUS frame-counter 312 RUNNING root@qemuarm64:~# echo | nc localhost 8080 frame-counter 1.0.0 camera0 frame 11
nc connects to port 8080, where the application writes its count and closes the connection.
Publishing the Images to a Registry
The same OCI image goes to a registry for the devices already in the field. meta-virtualization provides a class and a recipe, container-registry-index, that generate a helper script from a few settings of local.conf:
require conf/distro/include/container-registry.conf CONTAINER_REGISTRY_URL = "10.0.2.2:5000" CONTAINER_REGISTRY_TAG_STRATEGY = "semver latest"
container-registry.conf, shipped by meta-virtualization, defaults to an insecure registry, plain HTTP, with the namespace yocto. It adds the container-registry image feature, whose packages the host recipe sets. CONTAINER_REGISTRY_URL is the registry the devices use, here the build machine as QEMU shows it to the guest. CONTAINER_REGISTRY_TAG_STRATEGY decides which tags a push creates, and semver turns version 1.0.0 into the tags 1.0.0, 1.0 and 1.
A real registry uses TLS, and on Wrynose CONTAINER_REGISTRY_SECURE = "1" alone stops the parsing with an error, because the fragment also sets CONTAINER_REGISTRY_INSECURE ?= "1", so CONTAINER_REGISTRY_INSECURE = "0" is needed too. The build then generates a certificate authority and a server certificate, the registry runs in HTTPS, and the Docker host receives the authority in /etc/docker/certs.d/10.0.2.2:5000/ca.crt, and a pull then works over HTTPS with no other change on the device.
The script is generated by a task of the recipe, and its start command runs a registry compiled by the build, docker-distribution-native. On the build machine the registry is localhost:5000, which the variable overrides for the push; on a real project, the registry has one host name for both:
$ bitbake docker-distribution-native $ bitbake container-registry-index -c generate_registry_script $ export CONTAINER_REGISTRY_URL=localhost:5000 $ container-registry/container-registry.sh start $ container-registry/container-registry.sh push frame-counter-image --strategy "semver latest" --version 1.0.0 [...] Tags: 1.0.0 1.0 1 latest Image digest: sha256:df1a8dbca9c233ee675e4208000dbfdbda58b6ff7afc117b92ce8f90639ec9d1 -> localhost:5000/yocto/frame-counter-image:1.0.0 (manifest list) -> localhost:5000/yocto/frame-counter-image:1.0 (manifest list) -> localhost:5000/yocto/frame-counter-image:1 (manifest list) -> localhost:5000/yocto/frame-counter-image:latest (manifest list) [...]
The script pushes with a skopeo built by Yocto. After the application moves to 1.1.0, with the recipe renamed frame-counter_1.1.0.bb and the PV of the image set to 1.1.0, a rebuild and a second push give:
$ container-registry/container-registry.sh list [...] yocto/frame-counter-image: 1 1.0 1.0.0 1.1 1.1.0 latest yocto/frame-counter-image.rootfs: 1 1.0 1.0.0 1.1 1.1.0 latest
The tags 1 and latest now point to 1.1.0, while 1.0.0 stays available for a rollback. frame-counter-image.rootfs is the same image, pushed again under the other name it has in the deploy directory.
Updating the Application on the Device
A device that left the factory with 1.0.0 pulls 1.1.0 from the registry, gives it the name its service runs, and restarts the service. The update client of a fleet does the same through the API of the engine. Each engine needs the registry in its configuration, and the three hosts differ there.
On the Docker host, the build installed /etc/docker/daemon.json, which declares the registry insecure:
root@qemuarm64:~# cat /etc/docker/daemon.json
{
"insecure-registries": [
"10.0.2.2:5000"
]
}
root@qemuarm64:~# docker pull 10.0.2.2:5000/yocto/frame-counter-image:1.1.0
1.1.0: Pulling from yocto/frame-counter-image
8d545a3c1ed6: Pull complete
Digest: sha256:ea3d01adb63c45ef935d222b13a3d2054a5bde77dd94db05ab1e4f19ff4df0e3
Status: Downloaded newer image for 10.0.2.2:5000/yocto/frame-counter-image:1.1.0
10.0.2.2:5000/yocto/frame-counter-image:1.1.0
root@qemuarm64:~# docker images
i Info → U In Use
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
10.0.2.2:5000/yocto/frame-counter-image:1.1.0
fbaabe9a8d55 7.29MB 0B
frame-counter-image:latest ca45123e968d 7.29MB 0B U
root@qemuarm64:~# docker tag 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 frame-counter-image:latest
root@qemuarm64:~# systemctl restart container-frame-counter-image
root@qemuarm64:~# sleep 20; docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7e0a9e352c6 frame-counter-image:latest "/usr/bin/frame-coun…" 20 seconds ago Up 19 seconds 8080/tcp frame-counter-image
root@qemuarm64:~# docker logs frame-counter-image | tail -1
frame-counter 1.1.0: camera0 frame 2
The pulled image has a new ID, fbaabe9a8d55, and the factory one, still in use (U), keeps the name the service runs until docker tag moves it.
On the Podman host, it installed a drop-in file of /etc/containers/registries.conf.d:
root@qemuarm64:~# cat /etc/containers/registries.conf.d/50-custom-registry.conf [...] unqualified-search-registries = ["10.0.2.2:5000"] [[registry]] location = "10.0.2.2:5000" insecure = true root@qemuarm64:~# podman pull 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 Trying to pull 10.0.2.2:5000/yocto/frame-counter-image:1.1.0... Getting image source signatures Copying blob 8d545a3c1ed6 done | Copying config fbaabe9a8d done | Writing manifest to image destination fbaabe9a8d551e088bd691ca5136c142ff1cf38c97e8beaa2ec2020146e42e69 root@qemuarm64:~# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/frame-counter-image latest ca124fb3ba09 15 years ago 5.95 MB 10.0.2.2:5000/yocto/frame-counter-image 1.1.0 fbaabe9a8d55 15 years ago 7.65 MB root@qemuarm64:~# podman tag 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 docker.io/library/frame-counter-image:latest root@qemuarm64:~# systemctl restart container-frame-counter-image root@qemuarm64:~# sleep 20; podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 530b5eaab611 docker.io/library/frame-counter-image:latest camera0 22 seconds ago Up 21 seconds 8080/tcp frame-counter-image root@qemuarm64:~# podman logs frame-counter-image | tail -1 frame-counter 1.1.0: camera0 frame 3
The new version takes the fully qualified name of the bundled image. “15 years ago” is the fixed date OE-core gives reproducible builds. The containerd host got the same registries.conf.d file, which Podman and CRI-O read but containerd does not, and no /etc/containerd configuration. nerdctl then needs --insecure-registry, and ctr retags the image for the service:
root@qemuarm64:~# nerdctl pull --insecure-registry 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 WARN[0000] skipping verifying HTTPS certs for "10.0.2.2:5000" INFO[0001] fetch failed error="failed to do request: Head \"https://10.0.2.2:5000/v2/yocto/frame-counter-image/manifests/1.1.0\": http: server gave HTTP response to HTTPS client" host="10.0.2.2:5000" WARN[0001] server "10.0.2.2:5000" does not seem to support HTTPS, falling back to plain HTTP [...] 10.0.2.2:5000/yocto/frame-counter-image:1.1.0: resolved |++++++++++++++++++++++++++++++++++++++| index-sha256:ea3d01adb63c45ef935d222b13a3d2054a5bde77dd94db05ab1e4f19ff4df0e3: done |++++++++++++++++++++++++++++++++++++++| manifest-sha256:5f7bd6d7f8a38560ab3e0dde64349a4413751a4b78453ab632ba3184b282bf14: done |++++++++++++++++++++++++++++++++++++++| config-sha256:fbaabe9a8d551e088bd691ca5136c142ff1cf38c97e8beaa2ec2020146e42e69: done |++++++++++++++++++++++++++++++++++++++| layer-sha256:8d545a3c1ed681dc61e3b9bfffe3031c0ab5f6f8cf1c575e705b3e81addfc608: done |++++++++++++++++++++++++++++++++++++++| elapsed: 4.5 s total: 1.8 Ki (410.0 B/s) root@qemuarm64:~# ctr images ls -q 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 localhost/frame-counter-image:latest root@qemuarm64:~# ctr images tag --force 10.0.2.2:5000/yocto/frame-counter-image:1.1.0 localhost/frame-counter-image:latest localhost/frame-counter-image:latest root@qemuarm64:~# systemctl restart frame-counter-ctr root@qemuarm64:~# sleep 20; ctr task ls TASK PID STATUS frame-counter 419 RUNNING root@qemuarm64:~# echo | nc localhost 8080 frame-counter 1.1.0 camera0 frame 3
The build put the storage of each engine, /var/lib/docker, /var/lib/containers or /var/lib/containerd, in the root file system. A product moves it to a data partition, outside the root file systems of an A/B update scheme, so that the images pulled in the field survive an update of the base system.
The images bundled at build time then disappear behind the mount. With an empty file system mounted on /var/lib/docker, the Docker host started with no image and no container. Such a product installs the factory image as an OCI archive and imports it at first start, as the containerd host does.
Root Access Through the Engine Socket
The socket of a rootful engine, /run/docker.sock or the socket of containerd, gives root on the device to whoever can write to it. A member of the docker group, or the update client with the socket mounted in its container, can start a container as user 0 with the root file system of the host mounted inside, and read or change any file of the device. Mount the socket only in the containers that drive the engine. Docker and Podman can also run as an ordinary user, and our article on rootless Docker and Podman builds such hosts with Yocto.
meta-virtualization After Wrynose
The hosts of this article were built and tested with the wrynose branch of meta-virtualization at commit f27e2594. Its master branch, also compatible with Wrynose, adds container-nonroot-user, which creates a user nonroot with ID 65532 in the image and could replace the bare UID 1000 of our recipe.
While writing this article, we sent a two-patch series to meta-virtualization for two of the problems shown above. The first drops the patch of check-config.sh whose hunk broke the script, and it is merged in master as f2c984be. The second made CONTAINER_REGISTRY_SECURE = "1" enough on its own. The maintainer fixed that problem in another way, with a container-registry-secure.conf fragment in master, 8f20dd54, which a TLS registry requires in place of container-registry.conf. On our Docker host built with it, the pull over HTTPS works.
master at that commit also turns autostart into Restart=always for Docker and Podman. The registry configuration still has nothing for containerd, and FEATURE_PACKAGES_container-registry is still set only in container-image-host. On Wrynose, the workarounds given above still apply.
Summing Up
Check the kernel of the BSP with check-config.sh and read its required section, even though the script installed by meta-virtualization stops early. Choose the engine with BUILD_PROFILE, and write a host image recipe that inherits container-cross-install and sets FEATURE_PACKAGES_container-registry, two things container-image-host does for its own image only. Write each application image with explicit OCI_IMAGE_* variables, and install the factory versions with BUNDLED_CONTAINERS for Docker and Podman or with a recipe and a service for containerd.
Give each bundled container a restart policy that systemd knows, such as always, handle SIGTERM in the applications, give containerd its own registry configuration, and replace the policy.json that accepts every image. Publish with the generated registry script and a semver strategy, keep the storage of the engine on a data partition, and keep the engine socket away from every container that does not drive the engine.
Do your devices run their applications in containers, and how do you update them? Tell us in the comments.


