Package the Go binary with a distroless base

July 3, 2026 ยท View on GitHub

Rules to build container images from layers.

Use image_from_binary to package any *_binary target into a container image, image_manifest to create a single-platform container image from layers, and image_index to compose a multi-platform container image index.

INHERIT_FROM_BASE is a sentinel that can be used as (or inside) the user, working_dir, stop_signal, entrypoint, and cmd attributes of image_manifest / image_from_binary to explicitly inherit that config field from the base image.

image_index

load("@rules_img//img:image.bzl", "image_index")

image_index(name, annotations, annotations_file, build_settings, load_specs, manifests, platforms,
            push_specs, stamp, subject)

Creates a multi-platform OCI image index from platform-specific manifests.

This rule combines multiple single-platform images (created by image_manifest) into a multi-platform image index. The index allows container runtimes to automatically select the appropriate image for their platform.

The rule supports two usage patterns:

  1. Explicit manifests: Provide pre-built manifests for each platform
  2. Platform transitions: Provide one manifest target and a list of platforms

The rule produces:

  • OCI image index JSON file
  • An optional OCI layout directory or tar (via output groups)
  • ImageIndexInfo provider for use by image_push

Example (explicit manifests):

image_index(
    name = "multiarch_app",
    manifests = [
        ":app_linux_amd64",
        ":app_linux_arm64",
        ":app_darwin_amd64",
    ],
)

Example (platform transitions):

image_index(
    name = "multiarch_app",
    manifests = [":app"],
    platforms = [
        "//platform:linux-x86_64",
        "//platform:linux-aarch64",
    ],
)

Output groups:

  • digest: Digest of the image (sha256:...)
  • root_blob: The index JSON blob file
  • oci_layout: Complete OCI layout directory with all platform blobs
  • oci_tarball: OCI layout packaged as a tar file for downstream use
  • sparse_oci_layout: Sparse OCI layout directory (without layer blobs, only layer descriptors)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
annotationsArbitrary metadata for the image index.

Subject to template expansion.
Dictionary: String -> Stringoptional{}
annotations_fileFile containing annotations for the image index, as JSON or newline-delimited text.

The file is parsed in one of the following formats, auto-detected from its contents:

- JSON object with string values: {"key": "value"} - JSON object with list values: {"key": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["key=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim, so they can encode arbitrary strings including values that contain =, spaces, or newlines. The KEY=VALUE forms (JSON array and text) split on the first = and trim surrounding whitespace from the key and value.

Annotations from this file are merged with annotations specified via the annotations attribute. Values from the file take precedence over the annotations attribute for matching keys.

Example file content:
version=1.0.0
build.date=2024-01-15
source.url=https://github.com/...


Each annotation is subject to template expansion.
LabeloptionalNone
build_settingsBuild settings for template expansion.

Maps template variable names to string_flag targets. These values can be used in the annotations attribute using {{.VARIABLE_NAME}} syntax (Go template).

Example:
build_settings = {
"REGISTRY": "//settings:docker_registry",
"VERSION": "//settings:app_version",
}


See template expansion for more details.
Dictionary: String -> Labeloptional{}
load_specsLoad configurations to produce DeployInfo for this image index.

Each entry should be an image_load_spec target (providing LoadConfigInfo). When set (together with or without push_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.
List of labelsoptional[]
manifestsList of manifests for specific platforms.List of labelsoptional[]
platforms(Optional) list of target platforms to build the manifest for. Uses a split transition. If specified, the 'manifests' attribute should contain exactly one manifest.List of labelsoptional[]
push_specsPush configurations to produce DeployInfo for this image index.

Each entry should be an image_push_spec target (providing PushConfigInfo). When set (together with or without load_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.

For multi-platform pushes, manifest_tags on the push spec are expanded per child manifest with platform variables ({{.os}}, {{.architecture}}, etc.).
List of labelsoptional[]
stampControls build stamping for template expansion.

- auto (default): Defers to the global --@rules_img//img/settings:stamp setting. - force: Always stamp if templates contain {{}} placeholders, ignoring Bazel's --stamp flag. - disabled: Never include stamp information.

See template expansion for available stamp variables.
Stringoptional"auto"
subjectOptional subject for the index.

Sets the subject field in the OCI index, which is a descriptor pointing to another manifest or index. This is used for establishing referrer relationships, such as attaching SBOMs, signatures, or attestations to an existing image.

The target must provide either ImageManifestInfo or ImageIndexInfo.
LabeloptionalNone

image_manifest

load("@rules_img//img:image.bzl", "image_manifest")

image_manifest(name, annotations, annotations_file, artifact_type, base, build_settings, cmd,
               config_fragment, config_media_type, created, entrypoint, env, env_file, label_files,
               labels, layers, load_specs, platform, push_specs, stamp, stop_signal, subject, user,
               working_dir)

Builds a single-platform OCI container image from a set of layers.

This rule assembles container images by combining:

  • Optional base image layers (from another image_manifest or image_index)
  • Additional layers created by image_layer rules
  • Image configuration (entrypoint, environment, labels, etc.)

The rule produces:

  • OCI manifest and config JSON files
  • An optional OCI layout directory or tar (via output groups)
  • ImageManifestInfo provider for use by image_index or image_push

Example:

image_manifest(
    name = "my_app",
    base = "@distroless_cc",
    layers = [
        ":app_layer",
        ":config_layer",
    ],
    entrypoint = ["/usr/bin/app"],
    env = {
        "APP_ENV": "production",
    },
)

Output groups:

  • descriptor: OCI descriptor JSON file
  • digest: Digest of the image (sha256:...)
  • root_blob: The manifest JSON blob file
  • oci_layout: Complete OCI layout directory with blobs
  • oci_tarball: OCI layout packaged as a tar file for downstream use
  • sparse_oci_layout: Sparse OCI layout directory (without layer blobs, only layer descriptors)
  • mtree: a single mtree text file describing the image's filesystem, merged (in layer order) from per-layer mtrees. Layers built by rules_img layer rules reuse their own mtree; for any other layer -- pulled/imported base-image layers, or raw tars added directly via DefaultInfo -- an mtree is rendered on the fly from the layer's tar blob. A layer is skipped on a best-effort basis only when its blob is unavailable (shallow/lazy layers) or is not a tar (empty layers, non-tar artifact blobs), so a skipped layer means the merged mtree reflects only a subset of the image. Only produced when at least one layer contributes an mtree.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
annotationsThis field contains arbitrary metadata for the manifest.

Subject to template expansion.
Dictionary: String -> Stringoptional{}
annotations_fileFile containing annotations for the manifest, as JSON or newline-delimited text.

The file is parsed in one of the following formats, auto-detected from its contents:

- JSON object with string values: {"key": "value"} - JSON object with list values: {"key": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["key=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim, so they can encode arbitrary strings including values that contain =, spaces, or newlines. The KEY=VALUE forms (JSON array and text) split on the first = and trim surrounding whitespace from the key and value.

Annotations from this file are merged with annotations specified via the annotations attribute. Values from the file take precedence over the annotations attribute for matching keys.

Example file content:
version=1.0.0
build.date=2024-01-15
source.url=https://github.com/...


Each annotation is subject to template expansion.
LabeloptionalNone
artifact_typeOptional IANA media type of the artifact when the manifest is used for an artifact.

This sets the artifactType field in the OCI manifest, as defined in the OCI Image Spec.

Common values include application/vnd.cncf.helm.chart.v1 for Helm charts or application/spdx+json for SPDX SBOMs.
Stringoptional""
baseBase image to inherit layers from. Should provide ImageManifestInfo or ImageIndexInfo.LabeloptionalNone
build_settingsBuild settings for template expansion.

Maps template variable names to string_flag targets. These values can be used in env, labels, and annotations attributes using {{.VARIABLE_NAME}} syntax (Go template).

Example:
build_settings = {
"REGISTRY": "//settings:docker_registry",
"VERSION": "//settings:app_version",
}


See template expansion for more details.
Dictionary: String -> Labeloptional{}
cmdDefault arguments to the entrypoint of the container. These values act as defaults and may be replaced by any specified when creating a container. If an Entrypoint value is not specified, then the first entry of the Cmd array SHOULD be interpreted as the executable to run.

Defaults to [INHERIT_FROM_BASE]: the value is inherited from the base image (or, for image_from_binary, from the packaged binary's args). Set it to an explicit list to override, or to [] to unset it. An INHERIT_FROM_BASE item inside the list is replaced in place by the base image's cmd, so [INHERIT_FROM_BASE, "--flag"] appends "--flag" to it.
List of stringsoptional["<inherit from base>"]
config_fragmentOptional JSON file containing a partial OCI image config, which will be used as a base for the final image config.

For OCI image configuration fields such as exposed ports or volumes, the JSON should use the top-level config object:

{
"config": {
"ExposedPorts": {
"8080/tcp": {}
}
}
}


When config_media_type is set to a non-OCI type (e.g. Helm), this file is used as the entire config blob as-is.
LabeloptionalNone
config_media_typeOverride the config blob media type.

When set to "application/vnd.oci.empty.v1+json", config_fragment is optional. If omitted, an empty JSON config descriptor is produced automatically with the content inlined as data ("data": "e30=").

For other non-OCI types (e.g. "application/vnd.cncf.helm.config.v1+json" for Helm charts), config_fragment is required and used verbatim as the config blob (no OCI image structure).
Stringoptional""
createdOptional file containing a datetime string (RFC 3339 format) for when the image was created.

This is commonly used with Bazel's stamping mechanism to embed the build timestamp.
LabeloptionalNone
entrypointA list of arguments to use as the command to execute when the container starts. These values act as defaults and may be replaced by an entrypoint specified when creating a container.

Defaults to [INHERIT_FROM_BASE]: the entrypoint is inherited from the base image (or, for image_from_binary, from the packaged binary). Set it to an explicit list to override, or to [] to unset it. An INHERIT_FROM_BASE item inside the list is replaced in place by the base image's entrypoint, so [INHERIT_FROM_BASE, "--flag"] appends "--flag" to it.
List of stringsoptional["<inherit from base>"]
envDefault environment variables to set when starting a container based on this image.

Subject to template expansion.
Dictionary: String -> Stringoptional{}
env_fileFile containing environment variables to set when starting a container based on this image.

The file may be JSON or newline-delimited text, auto-detected from its contents:

- JSON object with string values: {"KEY": "value"} - JSON object with list values: {"KEY": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["KEY=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim and may contain =, spaces, or newlines. The KEY=VALUE forms split on the first = and trim surrounding whitespace.

Values from the env attribute (or expanded templates) take precedence over the file.
LabeloptionalNone
label_filesFiles containing labels for the image config, as JSON or newline-delimited text.

Each file is parsed in one of the following formats, auto-detected from its contents:

- JSON object with string values: {"key": "value"} - JSON object with list values: {"key": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["key=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim, so they can encode arbitrary strings including values that contain =, spaces, or newlines. The KEY=VALUE forms (JSON array and text) split on the first = and trim surrounding whitespace from the key and value.

Labels from these files are merged together, and then merged with labels specified via the labels attribute. Values from files take precedence over the labels attribute for matching keys.

Example file content:
org.opencontainers.image.version=1.0.0
org.opencontainers.image.authors=team@example.com


Each label value is subject to template expansion.
List of labelsoptional[]
labelsThis field contains arbitrary metadata for the container.

Subject to template expansion.
Dictionary: String -> Stringoptional{}
layersLayers to include in the image. Either a LayersInfo provider or a DefaultInfo with tar files.List of labelsoptional[]
load_specsLoad configurations to produce DeployInfo for this image.

Each entry should be an image_load_spec target (providing LoadConfigInfo). When set (together with or without push_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.

Example:
image_load_spec(
name = "load_config",
tag = "my-app:latest",
)

image_manifest(
name = "my_app",
base = "@distroless_cc",
layers = [":app_layer"],
load_specs = [":load_config"],
)

multi_deploy(
name = "deploy",
operations = [":my_app"],
)
List of labelsoptional[]
platformOptional target platform to build this manifest for.

When specified, the image will be built for the provided platform regardless of the current build configuration. This enables building single-platform images for specific architectures.

Example:
image_manifest(
name = "app_arm64",
platform = "//platforms:linux_arm64",
base = "@ubuntu",
layers = [":app_layer"],
)
LabeloptionalNone
push_specsPush configurations to produce DeployInfo for this image.

Each entry should be an image_push_spec target (providing PushConfigInfo). When set (together with or without load_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.

Example:
image_push_spec(
name = "push_config",
registry = "gcr.io",
repository = "my-project/my-app",
tag = "latest",
)

image_manifest(
name = "my_app",
base = "@distroless_cc",
layers = [":app_layer"],
push_specs = [":push_config"],
)

multi_deploy(
name = "deploy",
operations = [":my_app"],
)
List of labelsoptional[]
stampControls build stamping for template expansion.

- auto (default): Defers to the global --@rules_img//img/settings:stamp setting. - force: Always stamp if templates contain {{}} placeholders, ignoring Bazel's --stamp flag. - disabled: Never include stamp information.

See template expansion for available stamp variables.
Stringoptional"auto"
stop_signalThis field contains the system call signal that will be sent to the container to exit. The signal can be a signal name in the format SIGNAME, for instance SIGKILL or SIGRTMIN+3.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image. Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
Stringoptional"<inherit from base>"
subjectOptional subject for the manifest.

Sets the subject field in the OCI manifest, which is a descriptor pointing to another manifest or index. This is used for establishing referrer relationships, such as attaching SBOMs, signatures, or attestations to an existing image.

The target must provide either ImageManifestInfo or ImageIndexInfo.
LabeloptionalNone
userThe username or UID which is a platform-specific structure that allows specific control over which user the process run as. This acts as a default value to use when the value is not specified when creating a container.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image. Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
Stringoptional"<inherit from base>"
working_dirSets the current working directory of the entrypoint process in the container. This value acts as a default and may be replaced by a working directory specified when creating a container.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image (or, for image_from_binary, from the packaged binary). Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
Stringoptional"<inherit from base>"

image_optimize

load("@rules_img//img:image.bzl", "image_optimize")

image_optimize(name, compress, estargz, image)

Rewrites every available layer in an image manifest or image index.

This rule applies image-wide layer transformations, such as recompressing every layer as eStargz. It is intentionally explicit because it requires every input layer blob to be available to Bazel. Images that were pulled shallowly will fail analysis instead of downloading missing base-image layers.

Example:

load("@rules_img//img:image.bzl", "image_optimize")

image_optimize(
    name = "base_estargz",
    image = "@ubuntu//:image",
    estargz = "enabled",
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
compressCompression algorithm to use for rewritten layers. If set to 'auto', uses the global default compression setting.Stringoptional"auto"
estargzWhether to rewrite layers using eStargz. If set to 'auto', uses the global default eStargz setting.Stringoptional"auto"
imageImage manifest or image index to optimize. All layer blobs must be available.Labelrequired

image_from_binary

load("@rules_img//img:image.bzl", "image_from_binary")

image_from_binary(*, name, annotations, annotations_file, artifact_type, aspect_hints, base, binary,
                  build_settings, cmd, compatible_with, config_fragment, config_media_type, created,
                  deprecation, entrypoint, env, env_file, exec_compatible_with,
                  exec_group_compatible_with, exec_properties, features, include_runfiles, kind,
                  label_files, labels, layer_budget, layers, load_specs, package_metadata, path,
                  platforms, push_specs, restricted_to, stamp, stop_signal, subject, tags,
                  target_compatible_with, testonly, toolchains, user, visibility, working_dir)

Packages a *_binary target into a container image.

This is a convenience macro that combines layer_from_binary and image_manifest (or image_index) into a single target. It is the simplest way to containerize any Bazel *_binary target (Go, C++, Python, Java, Rust, etc.).

The binary's args, env, and runfiles are automatically extracted and applied to the image configuration:

  • entrypoint is set to the binary's path inside the image
  • cmd is populated from the binary's args attribute
  • env is populated from the binary's env attribute (or RunEnvironmentInfo provider)
  • working_dir is set to the binary's runfiles root

If the binary provides RunfilesGroupInfo (from rules_runfiles_group), the runfiles are split into separate layers based on the groups. This allows for better caching: stable layers (interpreter, stdlib) change infrequently and can be shared, while the application code layer changes with each build. The resolution protocol respects RunfilesGroupTransformInfo and RunfilesGroupMetadataInfo from the binary's aspect_hints.

All image_manifest attributes (base, env, labels, annotations, etc.) are inherited and forwarded to the underlying image_manifest. The binary layer is always appended as the last layer, after any layers specified in the layers attribute.

Example:

load("@rules_go//go:def.bzl", "go_binary")
load("@rules_img//img:image.bzl", "image_from_binary")

go_binary(
    name = "server",
    srcs = ["main.go"],
    env = {"GIN_MODE": "release"},
)

# Package the Go binary with a distroless base
image_from_binary(
    name = "app_image",
    binary = ":server",
    base = "@distroless_base",
)

# Custom path and additional layers
image_from_binary(
    name = "full_image",
    binary = "//cmd/server",
    base = "@ubuntu",
    path = "/usr/local/bin/",
    layers = [":config_layer"],
    env = {"LOG_LEVEL": "info"},
)

# Multi-platform image
image_from_binary(
    name = "multiarch_image",
    binary = "//cmd/server",
    base = "@distroless_base",
    platforms = [
        "//:linux_amd64",
        "//:linux_arm64",
    ],
)

Targets created:

  • <name>.layer: The layer_from_binary containing the executable and its runfiles
  • <name> (or <name>.manifest + <name> for multi-platform): The image manifest/index

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this macro instance. Normally, this is also the name for the macro's main or only target. The names of any other targets that this macro might create will be this name with a string suffix.Namerequired
annotationsThis field contains arbitrary metadata for the manifest.

Subject to template expansion.
Dictionary: String -> StringoptionalNone
annotations_fileFile containing annotations for the manifest, as JSON or newline-delimited text.

The file is parsed in one of the following formats, auto-detected from its contents:

- JSON object with string values: {"key": "value"} - JSON object with list values: {"key": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["key=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim, so they can encode arbitrary strings including values that contain =, spaces, or newlines. The KEY=VALUE forms (JSON array and text) split on the first = and trim surrounding whitespace from the key and value.

Annotations from this file are merged with annotations specified via the annotations attribute. Values from the file take precedence over the annotations attribute for matching keys.

Example file content:
version=1.0.0
build.date=2024-01-15
source.url=https://github.com/...


Each annotation is subject to template expansion.
LabeloptionalNone
artifact_typeOptional IANA media type of the artifact when the manifest is used for an artifact.

This sets the artifactType field in the OCI manifest, as defined in the OCI Image Spec.

Common values include application/vnd.cncf.helm.chart.v1 for Helm charts or application/spdx+json for SPDX SBOMs.
StringoptionalNone
aspect_hintsInherited rule attributeList of labelsoptionalNone
baseBase image to inherit layers from. Should provide ImageManifestInfo or ImageIndexInfo.LabeloptionalNone
binaryThe *_binary target to package into the image.

The binary's args and env attributes are extracted and applied as image configuration (cmd and env). The data attribute is used for $(location) expansion in args and env values.

If the binary provides RunfilesGroupInfo, the runfiles are split into separate layers per group.
Labelrequired
build_settingsBuild settings for template expansion.

Maps template variable names to string_flag targets. These values can be used in env, labels, and annotations attributes using {{.VARIABLE_NAME}} syntax (Go template).

Example:
build_settings = {
"REGISTRY": "//settings:docker_registry",
"VERSION": "//settings:app_version",
}


See template expansion for more details.
Dictionary: String -> LabeloptionalNone
cmdDefault arguments to the entrypoint of the container. These values act as defaults and may be replaced by any specified when creating a container. If an Entrypoint value is not specified, then the first entry of the Cmd array SHOULD be interpreted as the executable to run.

Defaults to [INHERIT_FROM_BASE]: the value is inherited from the base image (or, for image_from_binary, from the packaged binary's args). Set it to an explicit list to override, or to [] to unset it. An INHERIT_FROM_BASE item inside the list is replaced in place by the base image's cmd, so [INHERIT_FROM_BASE, "--flag"] appends "--flag" to it.
List of stringsoptionalNone
compatible_withInherited rule attributeList of labels; nonconfigurableoptionalNone
config_fragmentOptional JSON file containing a partial OCI image config, which will be used as a base for the final image config.

For OCI image configuration fields such as exposed ports or volumes, the JSON should use the top-level config object:

{
"config": {
"ExposedPorts": {
"8080/tcp": {}
}
}
}


When config_media_type is set to a non-OCI type (e.g. Helm), this file is used as the entire config blob as-is.
LabeloptionalNone
config_media_typeOverride the config blob media type.

When set to "application/vnd.oci.empty.v1+json", config_fragment is optional. If omitted, an empty JSON config descriptor is produced automatically with the content inlined as data ("data": "e30=").

For other non-OCI types (e.g. "application/vnd.cncf.helm.config.v1+json" for Helm charts), config_fragment is required and used verbatim as the config blob (no OCI image structure).
StringoptionalNone
createdOptional file containing a datetime string (RFC 3339 format) for when the image was created.

This is commonly used with Bazel's stamping mechanism to embed the build timestamp.
LabeloptionalNone
deprecationInherited rule attributeString; nonconfigurableoptionalNone
entrypointA list of arguments to use as the command to execute when the container starts. These values act as defaults and may be replaced by an entrypoint specified when creating a container.

Defaults to [INHERIT_FROM_BASE]: the entrypoint is inherited from the base image (or, for image_from_binary, from the packaged binary). Set it to an explicit list to override, or to [] to unset it. An INHERIT_FROM_BASE item inside the list is replaced in place by the base image's entrypoint, so [INHERIT_FROM_BASE, "--flag"] appends "--flag" to it.
List of stringsoptionalNone
envDefault environment variables to set when starting a container based on this image.

Subject to template expansion.
Dictionary: String -> StringoptionalNone
env_fileFile containing environment variables to set when starting a container based on this image.

The file may be JSON or newline-delimited text, auto-detected from its contents:

- JSON object with string values: {"KEY": "value"} - JSON object with list values: {"KEY": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["KEY=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim and may contain =, spaces, or newlines. The KEY=VALUE forms split on the first = and trim surrounding whitespace.

Values from the env attribute (or expanded templates) take precedence over the file.
LabeloptionalNone
exec_compatible_withInherited rule attributeList of labels; nonconfigurableoptionalNone
exec_group_compatible_withInherited rule attributeDictionary: String -> List of labels; nonconfigurableoptionalNone
exec_propertiesInherited rule attributeDictionary: String -> StringoptionalNone
featuresInherited rule attributeList of stringsoptionalNone
include_runfilesWhether to include runfiles for the binary target. When True (default), the binary's runfiles tree is included and the working directory is set to the runfiles root. Set to False for statically linked binaries that don't need runfiles.BooleanoptionalTrue
kindThe kind of image to produce.

* "auto": Creates a single-platform manifest if zero or one platforms are provided, otherwise creates an index. * "manifest": Always creates a single-platform manifest. Fails if multiple platforms are provided. * "index": Always creates a multi-platform index.
String; nonconfigurableoptional"auto"
label_filesFiles containing labels for the image config, as JSON or newline-delimited text.

Each file is parsed in one of the following formats, auto-detected from its contents:

- JSON object with string values: {"key": "value"} - JSON object with list values: {"key": ["value1", "value2"]} (the last value wins) - JSON array of KEY=VALUE strings: ["key=value"] - newline-delimited KEY=VALUE text (one per line; blank lines and # comments are ignored)

Values in JSON objects are used verbatim, so they can encode arbitrary strings including values that contain =, spaces, or newlines. The KEY=VALUE forms (JSON array and text) split on the first = and trim surrounding whitespace from the key and value.

Labels from these files are merged together, and then merged with labels specified via the labels attribute. Values from files take precedence over the labels attribute for matching keys.

Example file content:
org.opencontainers.image.version=1.0.0
org.opencontainers.image.authors=team@example.com


Each label value is subject to template expansion.
List of labelsoptionalNone
labelsThis field contains arbitrary metadata for the container.

Subject to template expansion.
Dictionary: String -> StringoptionalNone
layer_budgetMaximum number of runfiles group layers. If set to a value > 0 and the binary provides RunfilesGroupInfo, groups are merged down to this limit using the merge algorithm from rules_runfiles_group. The algorithm respects group rank (only merges within the same rank), do_not_merge flags, and weight hints (lighter groups merge first). 0 means no limit (all groups become separate layers).Integeroptional0
layersAdditional layers to include in the image. The binary layer is automatically appended to the end of this list.List of labelsoptional[]
load_specsLoad configurations to produce DeployInfo for this image.

Each entry should be an image_load_spec target (providing LoadConfigInfo). When set (together with or without push_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.

Example:
image_load_spec(
name = "load_config",
tag = "my-app:latest",
)

image_manifest(
name = "my_app",
base = "@distroless_cc",
layers = [":app_layer"],
load_specs = [":load_config"],
)

multi_deploy(
name = "deploy",
operations = [":my_app"],
)
List of labelsoptionalNone
package_metadataInherited rule attributeList of labels; nonconfigurableoptionalNone
pathOptional path of the binary inside the image. If the path ends with a slash ("/"), the basename of the binary will be automatically appended. If unset, this defaults to the rlocationpath of the binary (e.g., "main/cmd/server/server/server").Stringoptional""
platformsTarget platforms to build the image for. If empty, the image is built for the current target platform. If more than one platform is provided, an image_index is automatically created.List of labels; nonconfigurableoptional[]
push_specsPush configurations to produce DeployInfo for this image.

Each entry should be an image_push_spec target (providing PushConfigInfo). When set (together with or without load_specs), this rule additionally returns DeployInfo, making it directly usable as an operation in multi_deploy.

Example:
image_push_spec(
name = "push_config",
registry = "gcr.io",
repository = "my-project/my-app",
tag = "latest",
)

image_manifest(
name = "my_app",
base = "@distroless_cc",
layers = [":app_layer"],
push_specs = [":push_config"],
)

multi_deploy(
name = "deploy",
operations = [":my_app"],
)
List of labelsoptionalNone
restricted_toInherited rule attributeList of labels; nonconfigurableoptionalNone
stampControls build stamping for template expansion.

- auto (default): Defers to the global --@rules_img//img/settings:stamp setting. - force: Always stamp if templates contain {{}} placeholders, ignoring Bazel's --stamp flag. - disabled: Never include stamp information.

See template expansion for available stamp variables.
StringoptionalNone
stop_signalThis field contains the system call signal that will be sent to the container to exit. The signal can be a signal name in the format SIGNAME, for instance SIGKILL or SIGRTMIN+3.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image. Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
StringoptionalNone
subjectOptional subject for the manifest.

Sets the subject field in the OCI manifest, which is a descriptor pointing to another manifest or index. This is used for establishing referrer relationships, such as attaching SBOMs, signatures, or attestations to an existing image.

The target must provide either ImageManifestInfo or ImageIndexInfo.
LabeloptionalNone
tagsInherited rule attributeList of strings; nonconfigurableoptionalNone
target_compatible_withInherited rule attributeList of labelsoptionalNone
testonlyInherited rule attributeBoolean; nonconfigurableoptionalNone
toolchainsInherited rule attributeList of labelsoptionalNone
userThe username or UID which is a platform-specific structure that allows specific control over which user the process run as. This acts as a default value to use when the value is not specified when creating a container.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image. Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
StringoptionalNone
visibilityThe visibility to be passed to this macro's exported targets. It always implicitly includes the location where this macro is instantiated, so this attribute only needs to be explicitly set if you want the macro's targets to be additionally visible somewhere else.List of labels; nonconfigurableoptional
working_dirSets the current working directory of the entrypoint process in the container. This value acts as a default and may be replaced by a working directory specified when creating a container.

Defaults to INHERIT_FROM_BASE: the value is inherited from the base image (or, for image_from_binary, from the packaged binary). Set it to an explicit value to override, or to "" to unset it (do not inherit from the base).
StringoptionalNone