Skip to main content
Rugix Bakery 0.9.6 is here: Build rules for custom image pipelines and verified boot for EFI and Raspberry Pi. Read the release post.
Documentation

Docker Compose

Preview
You're viewing the Next docs — a rolling preview of in-development changes. The current release docs may differ.

The docker-compose orchestrator manages a set of containers defined by a Docker Compose file.

Getting Started

1. Write a Compose File

Create a standard docker-compose.yml. Use ${RUGIX_APP_DATA_DIR} for persistent data that should survive across updates:

docker-compose.yml
services:
  mosquitto:
    image: eclipse-mosquitto:2.1.2-alpine
    restart: unless-stopped
    ports:
      - "127.0.0.1:1883:1883"
    volumes:
      - ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ${RUGIX_APP_DATA_DIR}/mosquitto:/mosquitto/data

2. Pack the Bundle

Use rugix-bundler to package the application into an app bundle:

rugix-bundler apps pack docker-compose \
    --platform linux/arm64 \
    --app my-app \
    --include mosquitto.conf \
    docker-compose.yml \
    my-app-v1.rugixb

This command:

  1. Generates the app.toml manifest with orchestrator = "docker-compose".
  2. Copies registry images referenced in the compose file for the specified platform.
  3. Builds services with Compose build: entries using Podman by default.
  4. Saves each bundled image as a tarball so the bundle is fully self-contained. On the device, the tarball is kept in the store by default.
  5. Rewrites the packaged Compose file to Rugix-owned bundle-local image tags with pull_policy: never.
  6. Packages everything into a Rugix Bundle.

Image bundling requires skopeo on the build machine. Services with Compose build: entries additionally require the selected builder (podman by default, or docker when using --builder docker).

Options:

  • --pull only affects services with Compose build: entries. It passes --pull to Podman/Docker so Dockerfile FROM images are refreshed before building the service image. Services that only declare image: are copied by Skopeo and are unaffected.
  • --builder selects the builder for Compose build: entries. The default is podman; use --builder docker to build with Docker instead.
  • --platform targets the device architecture (e.g., linux/arm64, linux/amd64).
  • --include adds extra files or directories to the bundle.
  • --components adds component TOML or JSON files and directories to the bundle’s compatibility metadata.
  • --health-check-timeout writes the Docker Compose health-check timeout into app.toml. The default is 120 seconds; use 0 to disable waiting.
  • --config-schema and --config-default include the app’s optional JSON configuration contract.
  • --config-env NAME=JSON_POINTER projects a selected JSON scalar into the Compose interpolation environment. The option may be repeated.
  • --metadata-file includes an app metadata JSON file as app-meta.json.
  • --disable-image-bundling skips bundling container images, useful when devices pull images from a registry at runtime.
  • --disable-pinning keeps the Compose image: references as-is instead of rewriting them to Rugix-owned content tags. Images are still bundled under those original references. Deactivation does not remove them, because the references may also be used outside of the app.
  • --image-location selects where the device keeps the image tarballs: store (the default) keeps them in the store, and file writes them as files into the generation directory. Use file while devices may roll back to a Rugix Ctrl version without the store, which cannot read images kept in the store.

By default, services with build: entries are built locally and services with only image: entries are copied from a registry. To bundle an image that already exists in local container storage, add an x-rugix extension to the service:

services:
  worker:
    image: localhost/example/worker:dev
    x-rugix:
      image:
        source: containers-storage # or docker-daemon

Use x-rugix.image.ref only when the local source reference differs from the Compose image: reference.

Bundle a Prebuilt Image Archive

A docker-archive source packages an image created by docker save or Nix’s dockerTools without loading it into a local container daemon:

services:
  worker:
    image: example/worker:1
    x-rugix:
      image:
        source: docker-archive
        ref: images/worker.tar.gz

The archive path is required and resolves relative to the Compose file. Absolute paths are also accepted. Use an archive containing one image and a path without colons. Skopeo handles compressed archives. Normal bundling rewrites the image reference to a Rugix-owned content tag and includes the image as a separate payload. With --disable-pinning, provide a Compose image tag to retain.

For Nix builds, the Rugix flake exports lib.mkComposeBundle. It accepts Compose configuration and one image archive derivation per service, supplies Skopeo and Bundler, and produces the bundle plus its verification hash. See the Nix helper documentation for an example and the argument reference.

3. Install on the Device

rugix-ctrl apps install --bundle-hash HASH my-app-v1.rugixb

This writes the image tarballs into the store (or as files into the generation directory with --image-location file), streams them into docker image load, and runs docker compose up -d --wait.

4. Update

Update the compose file or image tags, pack a new bundle, and install it:

rugix-ctrl apps install --bundle-hash HASH my-app-v2.rugixb

The old generation is deactivated (docker compose down) and its Rugix-owned image tags are removed, then the new generation is activated (docker compose up -d --wait). The previous generation remains on disk for rollback. With the default --image-location store, the image tarballs of both generations stay in the store, which keeps their shared content once. Docker additionally holds the loaded images of the active generation.

Generation Directory

The generation directory must contain a docker-compose.yml file and may contain images/rugix-images.json, which records the tag of each bundled image. A generation may also have Docker image tarballs at images/NAME.tar, either in the generation directory or in the store. Activation loads each of them with docker image load.

When using rugix-bundler apps pack docker-compose, this structure is created automatically, with the image tarballs kept in the store unless you pass --image-location file.

Lifecycle Operations

The orchestrator drives Docker directly via docker compose and the Docker daemon. No service manager is involved.

OperationImplementation
activateLoads all images, then runs docker compose up -d --wait (see Health Checks).
statusChecks docker compose ps --format json output.
deactivateRuns docker compose down, then removes Rugix-owned image tags.
startRuns docker compose up -d --wait (without image loading).
stopRuns docker compose stop.
logsRuns docker logs for each container of the app (see Logs).

Boot behavior: Rugix Ctrl does not start Docker Compose apps at boot. Docker restarts the containers of an active app after a reboot only if their services set a restart policy, such as restart: unless-stopped. Without one, the app stays stopped until rugix-ctrl apps start starts it.

Boot behavior after stop: docker compose stop stops the containers but does not remove them. Whether Docker restarts them on boot depends on the restart policy in the compose file. With restart: always, Docker restarts the containers automatically. With restart: unless-stopped, Docker remembers that the containers were explicitly stopped and does not restart them.

Image removal on deactivation: Deactivation removes the Rugix-owned content tags recorded in images/rugix-images.json, so images of old generations do not accumulate. Removing the last tag of an image deletes the image. Activation loads the images again from the generation directory or the store, so rollbacks and configuration changes work without a registry.

Health Checks

During activation, docker compose up is called with --wait, which blocks until all containers with a healthcheck are healthy. If any container fails its health check, activation fails and the previous generation is automatically rolled back. Containers without a healthcheck are considered ready as soon as they are running.

The health check timeout defaults to 120 seconds and can be configured in app.toml:

app.toml
orchestrator = "docker-compose"

[health-check]
timeout = 120

Set timeout to 0 to disable waiting for health checks entirely (activation succeeds as soon as the containers are started).

Logs

rugix-ctrl apps logs reads the output of each container of the app’s Compose project with docker logs, including containers that have stopped. The source of a record is the Compose service of its container, stream is the stream to which the container wrote it, and generation is the generation whose docker-compose.yml created the container.

Docker deletes the logs of a container together with the container. Deactivation runs docker compose down, which removes the containers, and every update, rollback, and configuration change deactivates the previous generation. Its logs are therefore gone afterwards, unless a logging driver, such as journald, keeps them elsewhere. When activation fails, Rugix Ctrl saves the 500 most recent log records of the containers to .rugix/activation-logs.jsonl in the generation directory before it removes them. rugix-ctrl apps logs includes these records until the generation is removed, so the output of a failed update remains available after the rollback. Another failed activation of the same generation replaces them. Rugix Ctrl also saves the state and the recent output of the containers to .rugix/activation-diagnostics.log.

Environment Variables

The following environment variables are available in the docker-compose.yml:

VariableDescription
RUGIX_APP_DATA_DIRAbsolute path to the app’s persistent data directory.
RUGIX_APP_CONFIG_PATHAbsolute path to the effective JSON configuration, when one exists.

Projecting Configuration Values

Environment projection is specific to the Docker Compose orchestrator. Declare each variable explicitly when packing the app, using an RFC 6901 JSON Pointer:

rugix-bundler apps pack docker-compose \
    --app my-app \
    --config-schema config.schema.json \
    --config-env SERVER_URL=/serverUrl \
    docker-compose.yml \
    my-app.rugixb

Then use normal Compose interpolation:

docker-compose.yml
services:
  server:
    image: example/server
    environment:
      SERVER_URL: ${SERVER_URL:-https://default.example.com}

Only strings, numbers, and booleans can be projected. A missing or null value leaves the variable unset, allowing the Compose default to take effect. Objects and arrays cause activation to fail. Names beginning with RUGIX_ are reserved.

NixOS Integration

The Rugix flake exports nixosModules.rugix for app recovery and daemon services. Enabling services.rugix.apps.dockerCompose.enable also enables Rugix and Docker and declares the Compose runtime component. See the NixOS module guide for a configuration example.