Repolode
bazel-contrib

bazel-contrib/rules_img

Bazel rules for building OCI container images from Bazel targets, with shallow base image pulls, layer deduplication, and push strategies that avoid moving bytes through the local machine.

Open-source alternative to:Docker Build

Stars
144
Forks
58
Open issues
16
Last commit
yesterday

What is it?

rules_img is a set of Bazel rules for building OCI container images directly inside a Bazel build, without a Docker daemon. It supports both Bzlmod and WORKSPACE setups, and can package any *_binary target (C++, Go, Python, Java, Rust and others) into an image with entrypoint, cmd, env and working directory derived from the binary.

The project focuses on performance. Base images are pulled shallowly, so only the manifest and config are fetched and large layers such as CUDA are downloaded only when needed. Layers are produced in a single action, and identical files are deduplicated with hardlinks. Several push strategies (eager, lazy, CAS registry and BES) let images be uploaded from remote execution or the Bazel remote cache without passing through the local machine. It also supports multi-platform indexes, eStargz and SOCI lazy pulling, and filesystem and disk image layers.

Key features

  • 01Builds OCI images in Bazel without a Docker daemon, with hermetic builds.
  • 02Packages any *_binary target into a container image, setting entrypoint and cmd automatically.
  • 03Pulls base images shallowly, downloading only manifests and configs until layers are needed.
  • 04Deduplicates identical files across layers using hardlinks.
  • 05Offers multiple push strategies, including lazy pushes from the Bazel remote cache.
  • 06Supports multi-platform image indexes, eStargz and SOCI lazy pulling.

Use cases

  • Building container images for services written in C++, Go, Python or Java within an existing Bazel monorepo.
  • Shipping large GPU images such as CUDA-based workloads without downloading every base layer on each build machine.
  • Pushing images from CI or remote execution clusters to a registry without copying layers to the build host.
  • Producing multi-architecture images for linux/amd64 and linux/arm64 from one Bazel configuration.

Quick start

  1. 1

    Add rules_img to your MODULE.bazel file

  2. 2

    Optionally configure default settings in your .bazelrc file

Things to know

  • The current version is 0.3.x, so the API may still change between releases.
  • Several features, such as disk images, are marked experimental.

Topics

FAQ

What is rules_img?
Bazel rules for building OCI container images from Bazel targets, with shallow base image pulls, layer deduplication, and push strategies that avoid moving bytes through the local machine. rules_img is a set of Bazel rules for building OCI container images directly inside a Bazel build, without a Docker daemon. It supports both Bzlmod and WORKSPACE setups, and can package any *_binary target (C++, Go, Python, Java, Rust and others) into an image with entrypoint, cmd, env and working directory derived from the binary.
Is rules_img free to use? What license does it have?
rules_img is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is rules_img still maintained?
Actively maintained. The last commit to rules_img was on Nov 6, 2026.
What can I use rules_img for?
Building container images for services written in C++, Go, Python or Java within an existing Bazel monorepo. Shipping large GPU images such as CUDA-based workloads without downloading every base layer on each build machine. Pushing images from CI or remote execution clusters to a registry without copying layers to the build host. Producing multi-architecture images for linux/amd64 and linux/arm64 from one Bazel configuration.
How do I install rules_img?
Add rules_img to your MODULE.bazel file Optionally configure default settings in your .bazelrc file
Where can I get rules_img?
The source code and installation instructions are on GitHub: https://github.com/bazel-contrib/rules_img

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects