updater is a Docker auto-update module. It pulls newer images,
recreates the containers running them, and restarts whatever depended on those containers. It
handles Compose projects, registry digest checks, and containers that must update themselves.
It works against the local Docker environment out of the box. Persistence, notifications, and self-upgrade behavior are adapters, so a host application provides only the parts it owns.
- Module
kit.getarcane.app/updater- Reference
- pkg.go.dev
go get kit.getarcane.app/updater@latestQuick start
Section titled “Quick start”Everything runs through a Service. The zero Config is valid:
import "kit.getarcane.app/updater"
service, err := updater.New(updater.Config{})if err != nil { return err}defer service.Close()
result, err := service.UpdateContainer(ctx, containerID, updater.Options{})To apply recorded pending updates instead of updating one named container:
store := updater.NewMemoryPendingStore(updater.ImageUpdateRecord{ ID: "sha256:old-image-id", Repository: "nginx", Tag: "1.27", HasUpdate: true, UpdateType: updater.UpdateTypeDigest,})
service, err := updater.New(updater.Config{PendingStore: store})if err != nil { return err}defer service.Close()
result, err := service.ApplyPending(ctx, updater.Options{})ApplyPending applies each pending update, then restarts the containers still running the images
it replaced. Options{DryRun: true} reports what would change without touching anything.
Configuring
Section titled “Configuring”Every Config field is a seam. If you leave one nil, the updater supplies a Docker-backed default.
For the purely optional fields, it skips that behavior. Override only what you own:
service, err := updater.New(updater.Config{ // Replace a default. DockerClientProvider: updater.NewDockerClientProvider(client.WithHost("tcp://docker-proxy:2375")), PendingStore: myStore,
// Add optional behavior. Notifier: myNotifier, // told about each successful update EventRecorder: myEvents, // receives lifecycle events SelfUpdater: myUpgrader, // handles the container we run in
// Restrict which containers are in scope. LabelPolicy: updater.LabelPolicy{ IsUpdateDisabledFunc: func(l map[string]string) bool { return l["updates"] == "off" }, },
OperationTimeout: 30 * time.Second,})| Field | Default when nil |
|---|---|
DockerClientProvider |
NewDockerClientProvider(), which reads the standard Docker environment variables |
ImagePuller |
NewImagePuller(provider), which uses Docker’s ImagePull API |
PendingStore |
NewMemoryPendingStore(), which starts empty |
RegistryDigestResolver |
NewRegistryDigestResolver(), which uses local Docker credentials |
RegistryTagLister |
NewRegistryTagLister(), which uses local Docker credentials |
ProjectUpdater |
NewDockerComposeProjectUpdater(provider), which shells out to docker compose |
LabelPolicy |
DefaultLabelPolicy(), merged field by field. UnmanagedReasonFunc has no default |
RunRecorder, Settings, Notifier, EventRecorder, UsedImageCollector |
Behavior disabled |
SelfUpdater |
Self-update targets fail with ErrSelfUpdaterRequired |
Logger |
slog.Default() |
LabelPolicy merges field by field. New applies DefaultLabelPolicy().Merge(config.LabelPolicy),
so overriding IsUpdateDisabledFunc above keeps the default tag policy and the self-update, agent,
server, Swarm, and stop-signal detection.
Set UnmanagedReasonFunc when another tool owns some containers’ updates. It returns a reason, or
"" when the updater may touch the container. Containers with a reason are always skipped, even
when a run ignores opt-outs.
Set SelfContainerID to the ID (or ID prefix) of the container your application runs in. That
container always goes to the SelfUpdater, whatever its labels.
Service.Close shuts down the Docker client that New created. If you supplied your own
DockerClientProvider, its lifecycle stays yours and Close does nothing.
How it works
Section titled “How it works”- Resolve a pullable image reference for each in-scope container. Image IDs and digest-pinned references are skipped, because pulling them again can never produce a newer image.
- Skip containers the
LabelPolicydisables, containers the host excludes throughSettingsProvider, Swarm tasks, and containersUnmanagedReasonFuncreports as owned by another tool. A user-requested run can skip the first two checks. See Overriding opt-outs. - Select a newer eligible version tag, or compare the configured tag’s digest. See the Tag policies tab.
- Pull the target image. Container-scoped and tag updates are pulled and recreated one dependency unit at a time. A unit is a set of containers joined by dependencies or a Compose project. The next unit is pulled only after the previous one is recreated, so a canceled run never leaves running containers on an image whose tag a pull already moved.
- Recreate the container. Compose services go through the
ProjectUpdater, grouped by project and then checked to confirm they no longer run the old image. Standalone containers are recreated directly, following the Docker and Compose rules for what to keep. See Standalone recreation. - Restart containers that depend on what just changed, in dependency order.
- Hand self-update targets to the
SelfUpdaterlast, since updating them may stop the calling process.
Scheduling, durable persistence, and user-facing notifications are not the module’s job. Supply adapters for those.
Standalone recreation
Section titled “Standalone recreation”- Stop the container with its configured stop signal.
- Rename it to
<name>-arcane-update-<unix time>so it is kept as a backup. - Create the replacement under the original name. Named, anonymous, and image-declared volumes
are reattached by name, so their data is kept. A
container:<id>network mode is rewritten to the owner’s name. - Start the replacement only if the original was running.
- Remove the backup once the replacement has started.
If create or start fails, the replacement is removed and the backup gets its original name back.
It is started again if it was running. A container created with --rm is removed by Docker when it
stops, so it has no backup. It is recreated from its old image ID instead.
Overriding opt-outs
Section titled “Overriding opt-outs”Options{IgnoreSettingsExclusions: true} is for runs a user asked for, such as a manual update.
It lets UpdateContainer and ApplyPending update the containers they target even when:
- the
SettingsProviderexcludes them, or - the
com.getarcaneapp.arcane.updaterlabel opts them out.
The exclusion and the label stay in place. Some checks still apply:
- Containers restarted only because a dependency changed still honor both opt-outs.
- Swarm tasks, unmanaged containers, and image IDs or digest-pinned references stay ineligible.
result, err := service.UpdateContainer(ctx, containerID, updater.Options{ IgnoreSettingsExclusions: true,})To restart containers still running replaced images yourself, pass a RestartTargets:
restarted, err := service.RestartContainersUsingOldImages(ctx, updater.RestartTargets{ ByOldID: map[string]string{"sha256:old-image-id": "nginx:1.27"}, ByOldRef: map[string]string{"nginx:1.26": "nginx:1.27"},})RestartTargets.IgnoreSettingsExclusions works like the Options field above.
Checking without updating
Section titled “Checking without updating”check, err := service.CheckContainerUpdate(ctx, containerID)if err != nil { return err}if check.UpdateAvailable { fmt.Printf("%s -> %s (%s)\n", check.CurrentRef, check.TargetRef, check.UpdateType)}CheckContainerUpdate and CheckImageUpdate never pull, recreate, or write pending records.
Status() returns a snapshot of the containers and projects currently being updated.
Container labels
Section titled “Container labels”The default LabelPolicy reads these labels. They are also exported from updater/labels.
| Label | Effect |
|---|---|
com.getarcaneapp.arcane.updater |
false (or 0, no, off) opts the container out of updates |
com.getarcaneapp.arcane.updater.strategy |
digest, tag, or auto |
com.getarcaneapp.arcane.updater.constraint |
Semver range for tag updates |
com.getarcaneapp.arcane.updater.tag-pattern |
Regex that selects tags and captures their version |
com.getarcaneapp.arcane.depends-on |
Comma-separated container names to restart in dependency order |
com.getarcaneapp.arcane.stop-signal |
Custom stop signal |
com.getarcaneapp.arcane / .agent |
Marks a self-update target, which is handed to the SelfUpdater |
Packages
Section titled “Packages”| Package | Contents |
|---|---|
updater |
Service, Config, the adapter interfaces, and the result types |
updater/refs |
Image reference normalization and pullability checks |
updater/digest |
OCI digest parsing and canonicalization |
updater/labels |
The container label keys and the functions that read them |
updater/registry |
Registry tag listing, digest lookups, and pull rate limits. FetchTags, FetchDigest, and FetchRegistryRateLimit take a registry.Request |
updater/types |
Policy, CheckRequest, CheckResult, and Compose adapter contracts |
updater/pkg/utils/tagpolicy |
Semantic-version tag selection |
Errors
Section titled “Errors”Match these with errors.Is: ErrContainerNotFound, ErrSelfUpdaterRequired,
ErrSelfUpdateContainer, ErrPendingStoreRequired, ErrImagePullerRequired,
ErrDockerClientProviderRequired, ErrNilDockerClient. New returns a *ConfigError naming the
Config field it could not accept.
By default the updater keeps a container’s configured tag and only follows that tag’s
digest. Tag policies let it move to a newer tag instead, for example from 3.1.2 to 3.2.0.
Strategies
Section titled “Strategies”| Strategy | Behavior |
|---|---|
| (omitted) | Follow the digest, unless a constraint or tag pattern is set |
digest |
Always follow the current tag’s digest |
tag |
Select a newer tag. Requires a valid tag policy |
auto |
Select a newer tag for stable, complete semantic versions such as 3.1.2 or v3.1.2. Moving tags (latest), partial versions (3, 3.1), and ambiguous prerelease or variant tags fall back to digest checks |
A constraint or tag pattern without a strategy behaves like auto.
Configure with labels
Section titled “Configure with labels”services: app: image: example/app:3.1.2-alpine labels: com.getarcaneapp.arcane.updater.strategy: tag com.getarcaneapp.arcane.updater.constraint: "3.x" com.getarcaneapp.arcane.updater.tag-pattern: '(?P<version>\d+\.\d+\.\d+)-alpine'Constraints
Section titled “Constraints”- Without a constraint, tag updates stay within the current major version, or within the
current minor version for
0.x. - An explicit constraint replaces that range.
- Prereleases require a constraint that admits them, such as
>=3.1.2-0 <4.0.0.
Tag patterns
Section titled “Tag patterns”- A pattern must match the entire tag.
- A named
versioncapture group extracts the semantic version from a variant tag such as3.1.2-alpine, so the variant is kept. - Without a capture group, the whole matched tag must be a semantic version.
Selection rules
Section titled “Selection rules”- The exact registry tag is kept when pulling.
- Candidate versions that are equal resolve to the lexically smallest tag.
- The current version is never replaced with an equal or older one.
- If no newer tag qualifies, the current tag is still checked for digest changes.
- Image IDs and digest-pinned references are ineligible, even with
Force. - Invalid rules or an incompatible current tag return an error.
Configure in code
Section titled “Configure in code”Tag policies come from the LabelPolicy.TagPolicyFunc. To use your own source:
import updatertypes "kit.getarcane.app/updater/types"
service, err := updater.New(updater.Config{ LabelPolicy: updater.LabelPolicy{ TagPolicyFunc: func(labels map[string]string) updatertypes.Policy { return updatertypes.Policy{Strategy: "auto", Constraint: ">=1.0.0 <2.0.0"} }, },})To check an image you already have a reference and policy for:
check, err := service.CheckImageUpdate(ctx, updatertypes.CheckRequest{ ImageRef: "example/app:3.1.2", CurrentDigest: "sha256:...", // optional; avoids a local Docker lookup Policy: updatertypes.Policy{Strategy: "tag", Constraint: "3.x"},})The selection logic is also available on its own in updater/pkg/utils/tagpolicy, as Resolve,
Select, and Version.
Pending updates and Compose
Section titled “Pending updates and Compose”ImageUpdateRecord.ContainerIDscopes a record to one container. Durable stores must include it in the record’s identity, so that two containers sharing an image can follow different rules. The built-in memory store already does this.ApplyPendingrechecks references, eligibility, and constraints before pulling. It pulls each distinct target once, and keeps records after a failure. It updates running containers only. UseUpdateContainerto update a stopped container.- Container-scoped and tag records are pulled and recreated one dependency unit at a time. A record is cleared only after every container it targets succeeded.
For Compose tag changes, implement types.ProjectImageUpdater on your ProjectUpdater:
UpdateServiceImages(ctx context.Context, projectID string, changes map[string]types.ServiceImageChange) errorThe adapter must check that the stored service image still matches ExpectedRef, store
TargetRef, and recreate the service. Return success only once both are done. The built-in
docker compose adapter supports digest updates only. Compose tag changes fail before pulling
unless a host adapter implements this interface.
Registry access
Section titled “Registry access”The default RegistryTagLister uses Docker configuration credentials and handles pagination,
requesting 1000 tags per page. The caller’s deadline applies to the whole listing; without one, it
falls back to 120 seconds. A partial listing is never treated as “up to date”. Replace
Config.RegistryTagLister to supply your own credentials or registry client.
To list tags yourself, call registry.FetchTags with a registry.Request. A nil Credential is
anonymous, and a nil HTTPClient uses http.DefaultTransport:
import "kit.getarcane.app/updater/registry"
tags, err := registry.FetchTags(ctx, registry.Request{ Host: "docker.io", Repository: "library/nginx",})