Pull with friendly name

July 17, 2026 ยท View on GitHub

Public API for rules_img module extensions.

images

images = use_extension("@rules_img//img:extensions.bzl", "images")
images.pull(name, digest, layer_handling, registries, registry, repository, tag)
images.settings(credential_helper, docker_config_path, downloader, hub_repo, image_repos)

Module extension for pulling container images in Bzlmod projects.

This extension enables declarative pulling of container images using Bazel's module system. Images are pulled once and shared across all modules, with automatic deduplication of blobs for efficient storage.

Example usage in MODULE.bazel:

images = use_extension("@rules_img//img:extensions.bzl", "images")

# Pull with friendly name
images.pull(
    name = "ubuntu",
    digest = "sha256:1e622c5f073b4f6bfad6632f2616c7f59ef256e96fe78bf6a595d1dc4376ac02",
    registry = "index.docker.io",
    repository = "library/ubuntu",
    tag = "24.04",
)

# Pull without name - use repository as identifier
images.pull(
    digest = "sha256:029d4461bd98f124e531380505ceea2072418fdf28752aa73b7b273ba3048903",
    registry = "gcr.io",
    repository = "distroless/base",
)

use_repo(images, "rules_img_images.bzl")

Access pulled images in BUILD files using the generated helper. The name attribute is optional - if not specified, use the repository value to reference the image:

load("@rules_img_images.bzl", "image")

image_manifest(
    name = "my_app",
    base = image("ubuntu"),  # References the friendly name
    ...
)

image_manifest(
    name = "my_other_app",
    base = image("distroless/base"),  # References the repository
    ...
)

The extension creates deduplicated blob repositories, so pulling multiple images from the same base only downloads shared layers once. The digest parameter is required for reproducibility.

TAG CLASSES

pull

Attributes

NameDescriptionTypeMandatoryDefault
nameFriendly name for the image (e.g., 'ubuntu', 'distroless-base').

This name is used to reference the image in your code via the image() helper function. If not specified, defaults to the repository name.
Nameoptional""
digestThe image digest for reproducible pulls (e.g., "sha256:abc123...").

When specified, the image is pulled by digest instead of tag, ensuring reproducible builds. The digest must be a full SHA256 digest starting with "sha256:".
Stringoptional""
layer_handlingStrategy for handling image layers.

This attribute controls when and how layer data is fetched from the registry.

Available strategies:

* shallow (default): Layer data is fetched only if needed during push operations, but is not available during the build. This is the most efficient option for images that are only used as base images for pushing.

* eager: Layer data is fetched in the repository rule and is always available. This ensures layers are accessible in build actions but is inefficient as all layers are downloaded regardless of whether they're needed. Use this for base images that need to be read or inspected during the build.

* lazy: Layer data is downloaded in a build action when requested. This provides access to layers during builds while avoiding unnecessary downloads, but requires network access during the build phase. EXPERIMENTAL: Use at your own risk.
Stringoptional"shallow"
registriesList of mirror registries to try in order.

These registries will be tried in order before the primary registry. Useful for corporate environments with registry mirrors or air-gapped setups.
List of stringsoptional[]
registryPrimary registry to pull from (e.g., "index.docker.io", "gcr.io").

If not specified, defaults to Docker Hub. Can be overridden by entries in registries list.
Stringoptional""
repositoryThe image repository within the registry (e.g., "library/ubuntu", "my-project/my-image").

For Docker Hub, official images use "library/" prefix (e.g., "library/ubuntu").
Stringrequired
tagThe image tag to pull (e.g., "latest", "24.04", "v1.2.3").

While optional, it's recommended to also specify a digest for reproducible builds.
Stringoptional""

settings

Attributes

NameDescriptionTypeMandatoryDefault
credential_helperCredential helper to use for registry authentication when the module extension runs the pull tool.

If omitted, the pull tool inherits $IMG_CREDENTIAL_HELPER (or $IMG_CREDENTIAL_HELPER_OCI_REGISTRY, which takes precedence) when present.
Stringoptional""
docker_config_pathPath to Docker-compatible registry authentication config.

If omitted, the pull tool inherits $REGISTRY_AUTH_FILE when present.
Stringoptional""
downloaderThe tool to use for downloading manifests and blobs if the current module is the root module.

Available options:

* img_tool (default): Uses the img tool for all downloads.

* bazel: Uses Bazel's native HTTP capabilities for downloading manifests and blobs.
Stringoptional"img_tool"
hub_repoControls visibility of the hub repository @rules_img_images.bzl for image access via the images macro.

Available options:

* auto (default): The hub repository is made visible if named repositories cannot be mapped in the current Bazel version. This means you either get @rules_img_images.bzl or one repository per image.

* enabled: Always create and expose the hub repository @rules_img_images.bzl for image access via the images macro.

* disabled: Do not create the hub repository.
Stringoptional"auto"
image_reposControls visibility of individual image repositories for direct access. Repos internally use the naming scheme img_ and are mapped via friendly names (i.e. "ubuntu") if possible.

Available options:

* auto (default): Individual image repositories are made visible if named repositories can be mapped in the current Bazel version. This means you either get one repository per image or @rules_img_images.bzl.

* enabled: Always expose individual image repositories for direct access.

* disabled: Do not expose individual image repositories.
Stringoptional"auto"