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:
- Check that Docker and Buildx are available.
- Prepare the selected builder and registry access.
- Build and export the versioned image.
- Pull the image on application hosts.
- 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
kamalnetwork 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
| Trigger | Consequence | Guard |
|---|---|---|
| Docker or Buildx is not installed or the Docker server is not running | Build, network setup, or container actions fail before deployment can start | The command layer checks Docker and Buildx before local build work; host commands report the Docker command failure. |
A target host has no kamal network | Proxy, application exec, or accessory containers cannot use the expected service network | Proxy 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 label | The container cannot start, or the host may run an image from the wrong service | Registry login runs before pulls, and image validation requires the configured service label. |
| Container or image labels do not match the configured service or destination | Status, rollout selection, or prune can target no resource or the wrong resource | Role labels and service filters form the runtime identity contract. |
| An accessory publishes a port without a bind address | The accessory can expose a port more broadly than the configuration allows | Accessory configuration rejects unbound publish settings and requires an explicit host address. |
Key files
| File | Why to read it |
|---|---|
| lib/…/base.rb | Defines the shared Docker command boundary and common host/container lookup helpers. |
| lib/…/commander.rb | Shows how configured runtime command objects are selected and reused by CLI flows. |
| lib/…/configuration.rb | Defines the service, version, image, host-state, and volume values consumed by runtime actions. |
| lib/…/app.rb | Shows how application intent becomes a Docker run command and how runtime status is read. |
| lib/…/accessory.rb | Shows the supporting-service runtime boundary, including ports, volumes, logs, and execution. |
| lib/…/proxy.rb | Shows how the host proxy is run on the shared network and kept across restarts. |
| lib/…/base.rb | Shows how image build and pull actions use Buildx and image identity checks. |
| lib/…/registry.rb | Shows local registry setup and remote registry login or logout behavior. |
| lib/…/boot.rb | Shows how the application deployment flow uses runtime commands to start and verify a version. |
| lib/…/build.rb | Shows the build, registry, pull, and host distribution flow. |