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:
- Explicit manifests: Provide pre-built manifests for each platform
- 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 fileoci_layout: Complete OCI layout directory with all platform blobsoci_tarball: OCI layout packaged as a tar file for downstream usesparse_oci_layout: Sparse OCI layout directory (without layer blobs, only layer descriptors)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| annotations | Arbitrary metadata for the image index. Subject to template expansion. | Dictionary: String -> String | optional | {} |
| annotations_file | File 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: Each annotation is subject to template expansion. | Label | optional | None |
| build_settings | Build 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: See template expansion for more details. | Dictionary: String -> Label | optional | {} |
| load_specs | Load 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 labels | optional | [] |
| manifests | List of manifests for specific platforms. | List of labels | optional | [] |
| 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 labels | optional | [] |
| push_specs | Push 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 labels | optional | [] |
| stamp | Controls 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. | String | optional | "auto" |
| subject | Optional 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. | Label | optional | None |
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 filedigest: Digest of the image (sha256:...)root_blob: The manifest JSON blob fileoci_layout: Complete OCI layout directory with blobsoci_tarball: OCI layout packaged as a tar file for downstream usesparse_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 ownmtree; for any other layer -- pulled/imported base-image layers, or raw tars added directly viaDefaultInfo-- 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 anmtree.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| annotations | This field contains arbitrary metadata for the manifest. Subject to template expansion. | Dictionary: String -> String | optional | {} |
| annotations_file | File 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: Each annotation is subject to template expansion. | Label | optional | None |
| artifact_type | Optional 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. | String | optional | "" |
| base | Base image to inherit layers from. Should provide ImageManifestInfo or ImageIndexInfo. | Label | optional | None |
| build_settings | Build 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: See template expansion for more details. | Dictionary: String -> Label | optional | {} |
| cmd | Default 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 strings | optional | ["<inherit from base>"] |
| config_fragment | Optional 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: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. | Label | optional | None |
| config_media_type | Override 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). | String | optional | "" |
| created | Optional 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. | Label | optional | None |
| entrypoint | A 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 strings | optional | ["<inherit from base>"] |
| env | Default environment variables to set when starting a container based on this image. Subject to template expansion. | Dictionary: String -> String | optional | {} |
| env_file | File 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. | Label | optional | None |
| label_files | Files 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: Each label value is subject to template expansion. | List of labels | optional | [] |
| labels | This field contains arbitrary metadata for the container. Subject to template expansion. | Dictionary: String -> String | optional | {} |
| layers | Layers to include in the image. Either a LayersInfo provider or a DefaultInfo with tar files. | List of labels | optional | [] |
| load_specs | Load 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: | List of labels | optional | [] |
| platform | Optional 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: | Label | optional | None |
| push_specs | Push 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: | List of labels | optional | [] |
| stamp | Controls 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. | String | optional | "auto" |
| stop_signal | This 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). | String | optional | "<inherit from base>" |
| subject | Optional 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. | Label | optional | None |
| user | The 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). | String | optional | "<inherit from base>" |
| working_dir | Sets 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). | String | optional | "<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
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| compress | Compression algorithm to use for rewritten layers. If set to 'auto', uses the global default compression setting. | String | optional | "auto" |
| estargz | Whether to rewrite layers using eStargz. If set to 'auto', uses the global default eStargz setting. | String | optional | "auto" |
| image | Image manifest or image index to optimize. All layer blobs must be available. | Label | required |
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
argsattribute - env is populated from the binary's
envattribute (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
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A 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. | Name | required | |
| annotations | This field contains arbitrary metadata for the manifest. Subject to template expansion. | Dictionary: String -> String | optional | None |
| annotations_file | File 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: Each annotation is subject to template expansion. | Label | optional | None |
| artifact_type | Optional 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. | String | optional | None |
| aspect_hints | Inherited rule attribute | List of labels | optional | None |
| base | Base image to inherit layers from. Should provide ImageManifestInfo or ImageIndexInfo. | Label | optional | None |
| binary | The *_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. | Label | required | |
| build_settings | Build 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: See template expansion for more details. | Dictionary: String -> Label | optional | None |
| cmd | Default 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 strings | optional | None |
| compatible_with | Inherited rule attribute | List of labels; nonconfigurable | optional | None |
| config_fragment | Optional 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: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. | Label | optional | None |
| config_media_type | Override 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). | String | optional | None |
| created | Optional 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. | Label | optional | None |
| deprecation | Inherited rule attribute | String; nonconfigurable | optional | None |
| entrypoint | A 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 strings | optional | None |
| env | Default environment variables to set when starting a container based on this image. Subject to template expansion. | Dictionary: String -> String | optional | None |
| env_file | File 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. | Label | optional | None |
| exec_compatible_with | Inherited rule attribute | List of labels; nonconfigurable | optional | None |
| exec_group_compatible_with | Inherited rule attribute | Dictionary: String -> List of labels; nonconfigurable | optional | None |
| exec_properties | Inherited rule attribute | Dictionary: String -> String | optional | None |
| features | Inherited rule attribute | List of strings | optional | None |
| include_runfiles | Whether 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. | Boolean | optional | True |
| kind | The 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; nonconfigurable | optional | "auto" |
| label_files | Files 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: Each label value is subject to template expansion. | List of labels | optional | None |
| labels | This field contains arbitrary metadata for the container. Subject to template expansion. | Dictionary: String -> String | optional | None |
| layer_budget | Maximum 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). | Integer | optional | 0 |
| layers | Additional layers to include in the image. The binary layer is automatically appended to the end of this list. | List of labels | optional | [] |
| load_specs | Load 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: | List of labels | optional | None |
| package_metadata | Inherited rule attribute | List of labels; nonconfigurable | optional | None |
| path | Optional 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"). | String | optional | "" |
| platforms | Target 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; nonconfigurable | optional | [] |
| push_specs | Push 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: | List of labels | optional | None |
| restricted_to | Inherited rule attribute | List of labels; nonconfigurable | optional | None |
| stamp | Controls 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. | String | optional | None |
| stop_signal | This 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). | String | optional | None |
| subject | Optional 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. | Label | optional | None |
| tags | Inherited rule attribute | List of strings; nonconfigurable | optional | None |
| target_compatible_with | Inherited rule attribute | List of labels | optional | None |
| testonly | Inherited rule attribute | Boolean; nonconfigurable | optional | None |
| toolchains | Inherited rule attribute | List of labels | optional | None |
| user | The 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). | String | optional | None |
| visibility | The 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; nonconfigurable | optional | |
| working_dir | Sets 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). | String | optional | None |