
Recall first from Packaging small images and securing them
- A multi-stage build copies selected build outputs into the runtime image and leaves the compiler behind.
- A multi-platform index points to separate images for each supported platform.
- Non-root credentials, read-only mounts, seccomp and AppArmor restrict different operations.
Who should own the running containers?
3 min readA single container is easy; a fleet needs orchestration and updates, so this lesson covers both.
A gateway application that reads a serial sensor can stop collecting data when its process exits. Linux process supervision can restart the service on that gateway. If the gateway loses power, starting the same image on a nearby machine restores collection only if that machine can reach the sensor and use its configuration. The hardware dependency determines whether scheduling on another machine can recover the function.
For one application tied to one board, a systemd service can start the container, bring it back after a crash and collect its console logs. A separate updater can assign and deliver releases to many devices with this arrangement. Even a large fleet of independent gateways may need only local supervision and a fleet updater. Installing a cluster scheduler on each gateway adds control-plane processes and operational work. That cost is hard to justify when the application always runs on the same board.
Docker Compose describes a related set of containers on one Docker host. The command you normally use with the Compose plugin is docker compose. The standalone implementation used docker-compose. A gateway might declare a collector, a local broker and an uploader in one Compose file, with each service's image and required configuration recorded there. Applying the file on a device creates or recreates services as needed, and the Docker engine can enforce their restart policies. Compose is useful when those services are released together and need a repeatable local configuration. For a fleet, another component must assign that configuration to devices and track whether they applied it.
k3s is a Kubernetes distribution packaged for smaller installations, including edge clusters. For workloads managed by a Deployment, Kubernetes reconciles the requested replicas and can schedule replacement Pods on eligible nodes. A site with several machines running stateless video-processing workers can benefit if those workers can access the video feeds from any eligible node. A workload that requires a particular camera device or local data directory needs placement rules and an explicit recovery plan. Account for the control plane, its datastore and the resources they consume alongside the application. Decide how the site operates if it loses connectivity to central management.
Nomad also schedules jobs across eligible client nodes. Its Docker task driver can run containers, and job constraints can restrict placement to clients with the needed attributes. It suits a site that needs cluster scheduling and uses Nomad's job model. Nomad still needs servers and clients and a plan for the services the jobs depend on. For either scheduler, write down what can move, how it reaches its inputs after a move and which data follows it. If every answer points back to the same device, local supervision is usually enough.
How a container release reaches a device
4 min readA container OTA release changes the application images and, when necessary, the configuration used to start them. In balena, a fleet application release can describe several services. The balena Supervisor on the device receives the desired release and uses the local engine to fetch images and manage the containers. The operator assigns the release remotely, while the device performs the download and activation locally. A device that is offline can continue running its installed application and pick up the desired release after reconnecting.
Keep a record that ties a version tag to the digest published for that release. A tag such as gateway:1.4.2 gives operators a version they can recognise. The registry can allow that tag to be reassigned, so pin the digest when an exact rollback matters. For a multi-architecture image, the index digest fixes the set of platform manifests, and the engine selects the manifest for the device platform. Verify the release on each supported hardware and software combination. For example, a Pi running a 64-bit OS and a BeagleBone Black running a 32-bit ARM OS need compatible images and may require different host interfaces or configuration.
Download the replacement before stopping the installed version when the update mechanism and available storage allow it. Confirm that the device can hold the old and new images together and still has room to operate. Activation may require a brief stop and start, especially when both versions need exclusive access to a device node. The updater should persist enough state to resume after a reboot and report which release is assigned, which is running and whether it passed validation. A failed download and a failed activation call for different responses. The former can often be retried while the old application continues to run. The latter may require replacing the candidate with the previous release.
Stage the rollout on a small set of devices that represent the hardware, host versions and link quality in the fleet. Agree on the checks before changing any devices. For a collector, a running container is an initial signal. A stronger check is that it opens the sensor and produces fresh samples that reach their expected destination. Set an observation window and define what triggers a pause. Track devices that are still offline or downloading separately from devices that have activated the release. Expand to the next group only when enough devices have reported a healthy result and the agreed failure criteria have been met.
To roll back, reassign the previous release and have the device recreate the affected containers from its recorded images. For a multi-service application, restore the compatible set of image references and launch settings together. Retaining the previous images locally lets the device use them even if the registry is unreachable. An offline device still needs a local rollback policy if it must recover before receiving any new instruction. Check the data path before widening deployment. If the candidate migrates a persistent database, the previous image must be able to read the migrated data or the product needs a tested restore procedure.
Going deeperImage transfer and lifecycle ownership
A regular registry pull can reuse image layers already stored on the device. It fetches a missing layer as a blob even if that layer is very similar to one already present. BalenaEngine supports balena's delta mechanism for compatible images when a delta is available. A delta represents changes relative to a source image the device already has. The engine reconstructs the target using that local content and the downloaded delta. When the necessary source or delta is unavailable, plan for a regular pull and its bandwidth requirements.
A Mender container deployment uses the Mender client and an installed container Update Module. The client receives the deployment and calls the module for local update actions. The module coordinates the container tooling and the release definition it supports, such as a Compose application in a Compose-based flow. Check what that module implements for download, activation and rollback, including whether deployment data contains images or the device fetches them from a registry. Layer reuse depends on how images get to the engine. Balena-style delta transfer is a capability of the specific delivery mechanism. In either flow, the device component that owns activation should also control which release is allowed to run after a reboot.
What belongs in the OTA payload?
4 min readUse container OTA for an application-only change when the release still works with the deployed kernel, device interfaces, container runtime and host configuration. Updating the gateway's uplink protocol or a library bundled in its application image can fit this path. The transfer can reuse local layers and the update can take effect after recreating the affected containers. The other services can continue running if they are compatible with the change. Verify this by comparing the candidate's requirements with the host versions actually present in the fleet.
A full-image A/B update writes a bootable system image to the inactive slot. The device reboots into that slot and confirms it after the required checks. With boot fallback configured, the previous slot provides a way back if the new system fails to boot or fails to confirm within the configured policy. Use the platform updater when the fix changes the host kernel, a host driver or the host container runtime, assuming the A/B payload covers that component. The storage layout needs room for two system slots, and activation entails a reboot. Network transfer size depends on how the updater delivers the image.
A gateway can use both. It can receive many application releases between host updates, with each application release declaring which host versions it supports. If a new kernel interface is required, update and validate the host before offering the dependent application release. Plan the reverse order too. A fallback to the previous host slot can leave the newer application on a shared data partition, so the recovered host must either support that application or select a compatible release. Shared persistent data needs its own recovery plan with either update mechanism.
Going deeperSystemd, cgroups v2 and the container service
The cgroups v2 hierarchy exposes controllers such as cpu, memory and pids. A cgroup's cgroup.controllers lists controllers available to enable for its children, and cgroup.subtree_control determines which of those controllers govern the child cgroups. A child cannot escape limits imposed by an ancestor. On a systemd host, let systemd manage the hierarchy it owns. If a runtime or service needs to manage child cgroups itself, systemd's Delegate=yes gives it a subtree to manage subject to the available controllers and ancestor limits. Delegation does not grant access to hardware or enable controllers the parent cannot pass down.
systemd-run creates a transient service for a command. It is useful for checking supervision and logging on a lab host. For a persistent Podman service, Quadlet reads a .container source file such as /etc/containers/systemd/gateway.container for the system manager and generates a corresponding .service unit. Image= belongs in [Container], while Restart=on-failure belongs in [Service]. The generated unit lets systemd supervise the workload using the container's declared configuration. Use one restart authority for the workload so intentional stops and updates can be coordinated.
The following example starts a foreground Podman container in a transient unit. Use a systemd-enabled Ubuntu VM or WSL2 instance. The shell inside the container prints a startup marker, waits and exits with a failure status. Pulling the image separately makes it easier to distinguish a registry error from an application failure.
sudo podman pull docker.io/library/busybox:stable
sudo systemd-run --unit=m6-container-demo --property=Restart=on-failure \
--property=RestartSec=2s --property=StandardOutput=journal \
--property=StandardError=journal \
/usr/bin/podman run --rm docker.io/library/busybox:stable \
sh -c 'echo container-started; sleep 5; exit 1'
After the first exit and restart delay, inspect the journal and restart count, then stop the demo. Repeated container-started messages show that the application ran again. The unit's restart count shows that systemd scheduled restarts. If the marker is missing, read the service's error messages before treating a rising restart count as evidence of recovery. An explicit stop ends the restart loop. The transient unit demonstrates supervision for this run. Quadlet can provide a persistent definition for a service that must start at boot.
sudo journalctl -u m6-container-demo.service -n 30 --no-pager
sudo systemctl show m6-container-demo.service -p NRestarts
sudo systemctl stop m6-container-demo.service
The next lesson, Documenting architecture with C4 and ADRs, shows how to record where release assignment and activation happen, and why the product uses its chosen supervision and update design.
Key takeaways
- Systemd supervises a local service, Docker Compose groups services on one host, and k3s and Nomad schedule workloads across eligible hosts.
- A device can download a container release before replacing the running application.
- A version tag identifies a release by convention, while a digest pins the exact image manifest or index.
- Container rollback restores the application image, and persistent data needs its own compatibility plan.
Reflect
- Explain to a colleague, in two sentences: choose between systemd, Docker Compose, k3s and Nomad for a given deployment.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Man pagecgroups(7): Linux control groups
- Kernel documentationControl Group v2: controllers and delegation
Official documentation first. Links checked when the lesson was published.