Testcontainers.Docker.Auth (testcontainers v2.3.1)

Copy Markdown View Source

Resolves Docker registry credentials from the user's Docker config file (typically ~/.docker/config.json) and returns a ready-to-send X-Registry-Auth header value.

Scope:

  • Only the auths map in config.json is supported.
  • Credential helpers (credsStore, credHelpers) are intentionally out of scope — if encountered, a debug log is emitted and nil is returned so the caller can fall back to anonymous access.

The DOCKER_CONFIG environment variable is honoured: when set, the config file is read from $DOCKER_CONFIG/config.json; otherwise the default path ~/.docker/config.json is used.

The header value is a URL-safe base64 encoding (without padding) of a JSON document describing the credentials, as specified by the Docker Engine API.

Summary

Functions

Returns the registry key that should be used for looking up credentials for the given image (Docker config convention).

Resolves registry credentials for the given image and returns the ready-to-send X-Registry-Auth header value, or nil if no matching credentials can be found.

Functions

registry_for_image(image)

@spec registry_for_image(String.t()) :: String.t()

Returns the registry key that should be used for looking up credentials for the given image (Docker config convention).

Unnamespaced or explicitly docker.io-hosted images resolve to https://index.docker.io/v1/; everything else resolves to the registry host component of the image reference.

resolve(image, config_path \\ nil)

@spec resolve(String.t(), String.t() | nil) :: String.t() | nil

Resolves registry credentials for the given image and returns the ready-to-send X-Registry-Auth header value, or nil if no matching credentials can be found.

config_path may be nil, in which case the default lookup logic is used (respecting the DOCKER_CONFIG environment variable).