Accessory service operations
Kamal manages accessories as separate Docker services that support an application. An accessory can run on selected hosts, keep its own files and data, and optionally receive traffic through kamal-proxy. Accessory operations are separate from the application deployment flow; see command execution, application deployment, proxy management, and container lifecycle for related systems.
Accessory scope
Service boundaries
An accessory is a named supporting service such as a database, cache, or monitoring process. Kamal gives it a service name and manages its container independently from the main application, so an application deploy does not update the accessory and accessory changes do not provide zero-downtime replacement.
Each accessory has its own image, environment, restart policy, network, and optional registry. It can also use host files, host directories, or other Docker volumes. Secret values are placed in an accessory-specific environment file before the container starts.
References: lib/…/accessory.yml• L1-10 lib/…/accessory.rb• L29-35 lib/…/accessory.rb• L15-30
Host placement
Kamal places each accessory on exactly one configured host set. The set can name a host, a host list, one or more roles, or one or more server tags. The command uses the hosts that belong to both the accessory and the current command selection.
This lets one accessory run on a dedicated machine while another runs on the same hosts as an application role. A bad placement rule fails configuration validation instead of silently choosing a host.
References: lib/…/accessory.rb• L1-12 lib/…/accessory.rb• L37-39 lib/…/accessory.rb• L242-274 lib/…/accessory.rb• L334-353
Accessory lifecycle
Lifecycle commands
The accessory command group controls the full service lifecycle. The normal path is boot for a new service, start and stop for an existing container, and restart for a stop followed by a start.
| Command | Purpose |
|---|---|
kamal accessory boot NAME | Prepare the host and create a new accessory container. NAME=all applies the action to every accessory. |
kamal accessory start NAME | Start an existing stopped container. |
kamal accessory stop NAME | Stop the running container. |
kamal accessory restart NAME | Stop and then start the container. |
kamal accessory reboot NAME | Pull the configured image and replace the existing container. |
kamal accessory remove NAME | Stop and remove the container, image, and accessory service directory after confirmation. |
kamal accessory details NAME | Show container details for the accessory. |
kamal accessory upgrade NAME | Reboot accessories as part of the Kamal 1.x to 2.0 network upgrade. |
References: lib/…/accessory.rb• L4-41 lib/…/accessory.rb• L77-133 lib/…/accessory.rb• L135-146 lib/…/accessory.rb• L241-253 lib/…/accessory.rb• L290-307
Boot sequence
Boot turns accessory configuration into a running service on each target host. It prepares access to the registry and Docker network, creates required host paths, uploads configured files and secrets, then starts the container.
When a proxy is configured for the accessory, boot also registers the running container with kamal-proxy. If a container already exists on a host, Kamal skips boot on that host rather than creating a second service with the same name.
The flow is:
flowchart TD
A[Accessory configuration] --> B[Select target hosts]
B --> C[Prepare registry and network]
C --> D[Create paths and upload files]
D --> E[Upload accessory secrets]
E --> F[Start accessory container]
F --> G{Proxy enabled?}
G -- Yes --> H[Register container with kamal-proxy]
G -- No --> I[Service ready]
H --> I
References: lib/…/accessory.rb• L4-39 lib/…/accessory.rb• L43-75 lib/…/accessory.rb• L362-370 lib/…/accessory.rb• L15-30
Reboot replacement
Reboot is the update path for an accessory image or its run settings. Kamal pulls the new image, stops and removes the old container, boots a new container, and then removes the old image only when Docker no longer needs it.
Reboot is a replacement operation, not a zero-downtime deployment. For an accessory that runs on several hosts, use the rolling upgrade option when each host must be handled one at a time.
References: lib/…/accessory.rb• L77-91 lib/…/accessory.rb• L290-307 lib/…/accessory.rb• L310-331
Accessory operations
Files and data
Accessory files and directories provide the service with configuration and persistent data. Kamal creates configured directories on the host, uploads configured files, applies their requested mode and owner, and mounts them into the accessory container.
Relative directory paths are kept under the accessory service area. A remove operation deletes that service directory, so use a separate volume when data must outlive accessory removal.
References: lib/…/accessory.rb• L65-103 lib/…/accessory.rb• L150-197 lib/…/accessory.rb• L43-75 lib/…/accessory.rb• L355-360
Logs and commands
Operators can inspect an accessory with details and read its logs with logs. Logs can be limited by time or line count, filtered by a text match, or followed from one host.
The exec command can run a command in the existing accessory container or in a short-lived container made from the same image and service settings. Interactive commands use SSH. The raw output option is useful when another tool must consume the command output, but it cannot be combined with interactive mode.
References: lib/…/accessory.rb• L135-146 lib/…/accessory.rb• L148-193 lib/…/accessory.rb• L195-227 lib/…/accessory.rb• L44-87
Proxy integration
An accessory can use the same kamal-proxy service as the application. Its proxy settings define how requests reach the accessory, while the accessory lifecycle controls when the route exists.
When a proxied accessory starts, Kamal points kamal-proxy at the running container. When it stops, Kamal removes that route. A reboot replaces the container and refreshes the route; removal stops the service first and then removes its route through the stop step.
sequenceDiagram
participant Operator
participant Accessory as Accessory lifecycle
participant Docker
participant Proxy as kamal-proxy
Operator->>Accessory: boot or start
Accessory->>Docker: Start accessory container
Accessory->>Proxy: Deploy service target
Proxy-->>Operator: Route traffic to accessory
Operator->>Accessory: stop or remove
Accessory->>Docker: Stop accessory container
Accessory->>Proxy: Remove service route
The proxy must be available before a proxied accessory can serve traffic. Proxy behavior and proxy container management are covered in proxy management.
References: lib/…/accessory.rb• L117-119 lib/…/proxy.rb• L20-28 lib/…/proxy.rb• L1-15 lib/…/accessory.rb• L94-125
Change checklist
When these files or sections are changed, remember to consider these:
- A change to accessory host selection must preserve the rule that exactly one of
host,hosts,role,roles,tag, ortagsselects placement. - A change to service naming or the
servicelabel must preserve container lookup for start, stop, logs, image cleanup, and proxy registration. - A change to proxy settings must keep accessory start, stop, reboot, and remove aligned with the kamal-proxy route state.
- A change to relative directory paths must account for both the Docker mount path and the service directory removed by
accessory remove. - A change to port publishing must retain an explicit bind address so a service is not exposed by an implicit security choice.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| More than one or no host selector is set | Configuration cannot choose a safe accessory placement. | Define exactly one placement selector. |
| A published port has no valid bind address | Configuration fails instead of guessing whether the port is private or public. | Use a full form such as 127.0.0.1:PORT:PORT or 0.0.0.0:PORT:PORT. |
boot runs where the named container already exists | Kamal skips that host and does not replace the existing container. | Use reboot when the container must be replaced. |
| A proxied accessory stops while its route remains registered | Requests can continue to target a stopped service. | Use the accessory stop or remove command so route cleanup runs with the container stop. |
| An accessory is removed with relative persistent directories | The accessory service directory and its data are deleted. | Store data in a separate volume when it must survive removal. |
Key files
| File | Why to read it |
|---|---|
| lib/…/accessory.rb | Defines the operator-facing lifecycle, inspection, command, log, and cleanup flows. |
| lib/…/accessory.rb | Defines accessory scope, host placement, service identity, data mounts, and proxy presence. |
| lib/…/accessory.rb | Shows the Docker service actions that the lifecycle invokes. |
| lib/…/proxy.rb | Shows the boundary between accessory lifecycle state and kamal-proxy route state. |
| lib/…/accessory.yml | Gives the supported accessory configuration model and its operating limits. |