Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal

Deploy web apps anywhere.

View on GitHub

17 documents · Updated Nov 16, 2026

docs / container-runtime

Container runtime integration

Kamal uses a shared Docker command layer to turn deployment configuration into actions on the local machine and target hosts. The layer selects images, prepares networks and registries, runs containers, and checks runtime state while higher-level commands control the deployment flow.

Runtime command model

Docker command abstraction

The Docker command abstraction builds safe, reusable Docker command arguments from configuration. Kamal::Commands::Base provides the common command shape and shared operations such as container lookup, directory setup, and Docker or Buildx checks. Kamal::Commander supplies the configured command objects to CLI flows, so the same runtime rules apply across application, accessory, proxy, builder, and registry work.

References: lib/…/base.rb• L1-19 lib/…/base.rb• L21-41 lib/…/commander.rb• L84-121

Local and remote execution

The runtime layer does not assume that Docker runs in one place. Build actions can use a local, remote, hybrid, or cloud Buildx target, while container actions run on deployment hosts through SSHKit. The command object describes the Docker action; the CLI decides whether to execute it locally or on a host.

References: lib/…/base.rb• L13-19 lib/…/builder.rb• L19-33 lib/…/remote.rb• L35-73 lib/…/commander.rb• L192-201

Configuration to runtime intent

Configuration is the source of runtime intent. It defines the service and version used for image names, the roles and hosts that receive application containers, and the options that become environment, volume, label, network, restart, and port settings. The command layer turns this intent into Docker arguments without owning the deployment policy itself.

References: lib/…/configuration.rb• L54-89 lib/…/configuration.rb• L180-230 lib/…/role.rb• L42-67 lib/…/accessory.rb• L29-62

Runtime resource boundaries

Images and registries

An image is the deployable unit that moves from a build context to a registry and then to target hosts. Kamal gives the image a versioned name and a latest-style name, builds or pulls it through the selected builder, and checks its service identity before a host uses it. See Image identity and registry handling for the image naming and registry path.

References: lib/…/configuration.rb• L192-205 lib/…/base.rb• L15-33 lib/…/base.rb• L53-60 lib/…/registry.rb• L1-17

Containers and services

The runtime treats an application role, an accessory, and the proxy as distinct container services. Each service receives a name and labels that let Kamal find the right container later. Application containers carry version identity, accessories provide long-running supporting services, and the proxy connects published traffic to the selected service container.

References: lib/…/app.rb• L16-35 lib/…/accessory.rb• L15-29 lib/…/proxy.rb• L10-24 lib/…/role.rb• L124-130

Network and host state

Kamal prepares a shared Docker network named kamal on hosts before it starts services that need to communicate. Host directories hold deployment state such as environment files, proxy configuration, application assets, and accessory data. These host resources connect the short-lived container action to the durable state needed for later starts, upgrades, and recovery.

References: lib/…/docker.rb• L37-40 lib/…/configuration.rb• L248-280 lib/…/boot.rb• L48-87 lib/…/proxy.rb• L4-21

Runtime flows

Image delivery flow

Image delivery turns source and builder intent into a named image that each target host can run. The local registry case adds a host-port path between the builder and remote systems; a remote registry instead uses login steps at the places that build or pull the image.

The flow has these stages:

  1. Check that Docker and Buildx are available.
  2. Prepare the selected builder and registry access.
  3. Build and export the versioned image.
  4. Pull the image on application hosts.
  5. Validate the image identity before use.

This diagram shows how build output reaches the runtime host.

flowchart LR
    Intent[Deployment and builder intent] --> Builder[Buildx target]
    Builder --> Registry[Image registry]
    Registry --> Host[Target host]
    Host --> Validate[Service identity check]
    Validate --> Container[Runnable container]

References: lib/…/build.rb• L4-24 lib/…/build.rb• L70-85 lib/…/build.rb• L189-212 lib/…/base.rb• L19-33

Container launch flow

Container launch combines a selected image with service-specific runtime settings. The application flow starts a versioned container and then checks health or registers it with the proxy; accessory and proxy flows use the same Docker boundary for their own long-running services. See Container lifecycle behavior for rollout, stop, remove, and recovery behavior.

This diagram shows the shared launch path and its two readiness outcomes.

sequenceDiagram
    participant CLI as Deployment command
    participant Host as Target host
    participant Docker as Docker runtime
    participant Check as Health or proxy check
    CLI->>Host: Prepare env and host state
    CLI->>Docker: Run image with service settings
    Docker-->>CLI: Container identity
    CLI->>Check: Verify health or register route
    Check-->>CLI: Ready or failure

References: lib/…/boot.rb• L14-32 lib/…/boot.rb• L46-60 lib/…/app.rb• L16-43 lib/…/accessory.rb• L15-37

Runtime inspection flow

Inspection keeps later actions tied to the intended service rather than to an arbitrary Docker object. Labels and names identify containers and images, while status and health output tells deployment code whether a new version is ready or an old version can be stopped. Prune actions use the same identity fields to remove stale resources without crossing service or destination boundaries.

References: lib/…/app.rb• L41-74 lib/…/containers.rb• L4-30 lib/…/prune.rb• L5-20 lib/…/role.rb• L212-235

Integration responsibilities

Application runtime

Application runtime actions use role configuration to create one container per deployed version and host. They pass environment and secret files, shared and asset volumes, labels, logging settings, restart policy, and the selected command into Docker. Proxy-enabled roles also expose the container to the proxy through a container-level command.

References: lib/…/app.rb• L16-35 lib/…/execution.rb• L10-23 lib/…/proxy.rb• L4-30 lib/…/role.rb• L93-115

Accessory runtime

Accessory runtime actions manage supporting services that may run beside application roles. An accessory can use its own image and registry, network, ports, volumes, files, environment, and restart policy. Its command path also supports one-off work in a new container or command reuse in the existing service container.

References: lib/…/accessory.rb• L1-29 lib/…/accessory.rb• L59-84 lib/…/accessory.rb• L29-115 lib/…/accessory.rb• L4-40

Proxy runtime

The proxy runtime is the host-level traffic entry point for services that use proxy routing. Kamal creates the shared network, starts the proxy container with persistent configuration, and sends application or accessory route commands through the proxy container. The proxy image and its boot settings are separate from application image delivery.

References: lib/…/proxy.rb• L10-24 lib/…/proxy.rb• L35-47 lib/…/proxy.rb• L4-18 lib/…/proxy.rb• L4-14

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep service and destination labels aligned with every container and image filter. A mismatch can make a live resource invisible to status or prune actions.
  • Keep versioned image names, latest image tags, and container-name parsing aligned. These values link image selection to rollout state.
  • Keep the kamal network contract aligned across proxy, application execution, and accessory configuration. A change in one path can isolate services from each other.
  • Keep local-registry port forwarding aligned with the selected remote builder. The builder and target host must reach the same registry endpoint.
  • Keep Docker and Buildx availability checks aligned with every command path that builds or exports an image.

Important failure modes

TriggerConsequenceGuard
Docker or Buildx is not installed or the Docker server is not runningBuild, network setup, or container actions fail before deployment can startThe command layer checks Docker and Buildx before local build work; host commands report the Docker command failure.
A target host has no kamal networkProxy, application exec, or accessory containers cannot use the expected service networkProxy and accessory preparation create the network and tolerate the already-exists result.
A host cannot pull the selected image or the image has the wrong service labelThe container cannot start, or the host may run an image from the wrong serviceRegistry login runs before pulls, and image validation requires the configured service label.
Container or image labels do not match the configured service or destinationStatus, rollout selection, or prune can target no resource or the wrong resourceRole labels and service filters form the runtime identity contract.
An accessory publishes a port without a bind addressThe accessory can expose a port more broadly than the configuration allowsAccessory configuration rejects unbound publish settings and requires an explicit host address.

Key files

FileWhy to read it
lib/…/base.rbDefines the shared Docker command boundary and common host/container lookup helpers.
lib/…/commander.rbShows how configured runtime command objects are selected and reused by CLI flows.
lib/…/configuration.rbDefines the service, version, image, host-state, and volume values consumed by runtime actions.
lib/…/app.rbShows how application intent becomes a Docker run command and how runtime status is read.
lib/…/accessory.rbShows the supporting-service runtime boundary, including ports, volumes, logs, and execution.
lib/…/proxy.rbShows how the host proxy is run on the shared network and kept across restarts.
lib/…/base.rbShows how image build and pull actions use Buildx and image identity checks.
lib/…/registry.rbShows local registry setup and remote registry login or logout behavior.
lib/…/boot.rbShows how the application deployment flow uses runtime commands to start and verify a version.
lib/…/build.rbShows the build, registry, pull, and host distribution flow.