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 / image-identity-and-registry

Image identity and registry handling

Kamal gives each deployment image a source-based version and a registry-based name. It uses that identity to build the image, publish it, and let each app server pull the same image before the deployment starts. This page explains the path between source revision, image tags, registry access, and container startup. See also container runtime, container lifecycle, image building, and service configuration.

Image identity

Source revision identity

The image version identifies the source used for a deployment. Kamal uses an explicit version when one is supplied. Otherwise it uses VERSION or the current Git revision. A dirty local checkout gets a unique suffix unless the build uses a clean Git clone, so an uncommitted build is not confused with its committed source.

The full version stays attached to the image name. Kamal also exposes a short revision for service metadata and operational tags. This gives operators a stable value to use when they inspect a running container or select a rollback version.

References: lib/…/configuration.rb• L93-109 lib/…/configuration.rb• L450-459 lib/…/git.rb• L16-22

Image naming

The image repository joins the registry server and the configured image name. The version tag forms the exact image reference used for build, pull, and container execution. A second destination-aware latest tag points to the most recent image for that deployment target.

Identity partPurpose
Registry serverSelects the image service. An omitted server uses the default registry.
Image nameSelects the application repository. A local registry can use the service name when no image name is set.
Version tagSelects one source revision for repeatable pulls and rollbacks.
Latest tagSelects the newest image for a destination. It is updated after the app boots.

Builds also add the service label to the image. Servers use that label as a guard after the pull, which helps prevent a valid but unrelated repository image from starting as the app.

References: lib/…/configuration.rb• L180-205 lib/…/base.rb• L75-94 lib/…/app.rb• L34-38

Registry access

Registry endpoints

The registry endpoint is the shared point between the build side and the app servers. A remote registry is addressed by its server name. A local registry is addressed through localhost and is started by Kamal for the deployment.

Local registries are useful when the build and deployment hosts can reach one another through an SSH tunnel. Kamal forwards the local registry port to a remote builder or to app servers as needed. A remote builder with a local registry must use an SSH URL so Kamal can create that path safely.

References: lib/…/registry.rb• L10-28 lib/…/registry.rb• L19-26 lib/…/configuration.rb• L408-413 lib/…/build.rb• L216-231

Registry authentication

Remote registries require a username and password. Each value can be written directly or can name one secret for local lookup. Kamal logs in on the build side before publication and on the app servers before they pull. Local registries do not need a login because Kamal owns the local registry process.

The registry configuration supports common remote registry patterns such as Docker Hub, AWS ECR, and Google Artifact Registry. The registry service receives the resulting credentials through Docker login rather than through the application container.

Registry kindAccess behavior
Local registryStart the local registry and use port forwarding. No registry login is needed.
Remote registryLog in locally and on deployment hosts before image transfer.
Secret-backed credentialsResolve each one-item credential reference from the configured secret store.

Use kamal registry setup for a local registry or for a remote login on both sides. The login and logout commands apply only to remote registries.

References: lib/…/registry.yml• L1-64 lib/…/registry.rb• L1-27 lib/…/registry.rb• L30-39 lib/…/registry.rb• L1-17 lib/…/registry.rb• L1-47

Build-to-pull path

Image publication

The build command turns the selected source into an image and publishes both the exact version tag and the destination-aware latest tag. The chosen builder can run locally, remotely, or across both locations for different CPU architectures. The registry remains the handoff point even when the builder is remote.

The normal delivery command runs publication first and server pulls second. This ordering makes the version available before any app server tries to start it.

This diagram shows how one source revision becomes the image selected by the deployment.

flowchart LR
    A[Source revision] --> B[Build target]
    B --> C[Version tag and latest tag]
    C --> D[Registry]
    D --> E[Registry login or port forwarding]
    E --> F[Pull exact image on app servers]
    F --> G[Validate service label]
    G --> H[Start deployment container]

References: lib/…/build.rb• L4-7 lib/…/build.rb• L20-67 lib/…/base.rb• L19-29 lib/…/builder.rb• L19-32

Server image acquisition

The pull step authenticates to the remote registry when needed. It can seed one host per configured registry mirror before it pulls on the other app hosts. On each host it removes the local copy of the exact version when needed, pulls the versioned image, and checks its service label.

Deployment normally resolves the newest destination tag when no version is given. A requested version instead selects that version tag directly. After all hosts boot successfully, Kamal moves the latest tag on each host to the image that just started.

References: lib/…/build.rb• L70-85 lib/…/build.rb• L174-195 lib/…/app.rb• L3-39 lib/…/base.rb• L31-59

Change checklist

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

  • Keep the version source and image tag rules aligned. A change to version precedence can change pull, rollback, container-name, and lock identities at the same time.
  • Keep the repository and latest-tag rules aligned with local registry naming. A mismatch can publish one reference and pull another.
  • Keep registry credential resolution consistent with both local builder login and remote host login.
  • Keep local-registry port forwarding aligned with remote-builder and app-server reachability.
  • Keep the service label check aligned with the label written during every supported build path.

Important failure modes

TriggerConsequenceGuard
A remote registry has no usable username or passwordRegistry validation stops the configuration before transfer.Supply direct values or one-item secret references.
A remote builder uses a local registry without an SSH URLKamal cannot provide a safe route to the registry.Use an SSH remote builder endpoint.
The published image has no matching service labelThe server rejects the image after pull.Ensure every build path writes the configured service label.
A local registry port is not forwarded to the builder or app hostsBuild or pull cannot reach the local registry.Keep SSH forwarding active for the full build or pull operation.
The requested version was not publishedThe server cannot pull the exact image reference.Run publication before pull, or select a version that exists in the registry.

Key files

FileWhy to read it
lib/…/configuration.rbDefines source version selection and the repository, version, and latest image references.
lib/…/registry.rbDefines registry endpoint and credential lookup behavior.
lib/…/registry.ymlShows the supported registry configuration patterns.
lib/…/base.rbDefines the shared image tags, publication command, pull command, and service-label check.
lib/…/build.rbConnects build, registry access, publication, port forwarding, and server pulls.
lib/…/registry.rbDefines local registry setup and remote registry login actions.
lib/…/app.rbShows how deployment selection uses the latest or requested version and updates the latest tag.