Bazel rules for building OCI containers
423
stars
422
commits
Starlark
primary language
Aug 28, 2026
updated
Very simple Bazel rules based on the Open Containers Initiative specification: https://opencontainers.org/
Status: Unfunded, stable in maintenance mode.
DefaultInfo to hand information between rules, meaning that files and directories are inputs/outputs for each action.As described above, rules_oci is built for maintainability on top of standard container tools. This means it doesn't attempt to make all the optimizations that are possible with rules_img.
For use with remote cache and remote execution, the use of files and directories as action input/output means that lots of bytes are sent over the network. For these cases, we recommend trying rules_img. See https://github.com/bazel-contrib/rules_img/blob/main/docs/migration-from-rules_oci.md to migrate from rules_oci to rules_img.
This ruleset is not intended as a complete replacement for rules_docker.
Most use cases can be accomodated, and we know many users who have completely replaced rules_docker.
However, some other use cases such as container_run_and*\* rules have no equivalent.
You might still decide to use rules_docker, and perhaps even volunteer to help maintain it.
You can find a migration guide at https://docs.aspect.build/guides/rules_oci_migration.
See the install instructions on the release notes: https://github.com/bazel-contrib/rules_oci/releases
To use a commit rather than a release, you can point at any SHA of the repo.
With bzlmod, you can use archive_override or git_override. For WORKSPACE, you modify the http_archive call; for example to use commit abc123 with a WORKSPACE file:
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v0.1.0/rules_oci-v0.1.0.tar.gz"
with a GitHub-provided source archive like url = "https://github.com/bazel-contrib/rules_oci/archive/abc123.tar.gz"strip_prefix = "rules_oci-0.1.0" with strip_prefix = "rules_oci-abc123"sha256. The easiest way to do this is to comment out the line, then Bazel will
print a message with the correct value.Note that GitHub source archives don't have a strong guarantee on the sha256 stability, see https://github.blog/2023-02-21-update-on-the-future-stability-of-source-code-archives-and-hashes
rules_oci does not contain language-specific rules, but we do have limited documentation on how to accomplish typical tasks.
[!NOTE] Your language not listed above? Please contribute engineering resources or financially through our Sponsor link!
There are some generic examples of usage in the examples folder.
Note that these examples rely on the setup code in the /WORKSPACE file in the root of this repo.
oci_image into a container daemon. Can optionally produce a loadable tarball.curl in some cases.oci_image or oci_image_index to a remote registry.[!WARNING]
Signing images is a developer preview, not part of public API yet.
oci_image using cosign binary at a remote registry.oci_image at a remote registry using cosign.(top 30 of 110)
Starlark
83.5%
Shell
15.3%
Go
1.1%
Bazel rules for building OCI containers
423
stars
422
commits
Starlark
primary language
Aug 28, 2026
updated
Very simple Bazel rules based on the Open Containers Initiative specification: https://opencontainers.org/
Status: Unfunded, stable in maintenance mode.
DefaultInfo to hand information between rules, meaning that files and directories are inputs/outputs for each action.As described above, rules_oci is built for maintainability on top of standard container tools. This means it doesn't attempt to make all the optimizations that are possible with rules_img.
For use with remote cache and remote execution, the use of files and directories as action input/output means that lots of bytes are sent over the network. For these cases, we recommend trying rules_img. See https://github.com/bazel-contrib/rules_img/blob/main/docs/migration-from-rules_oci.md to migrate from rules_oci to rules_img.
This ruleset is not intended as a complete replacement for rules_docker.
Most use cases can be accomodated, and we know many users who have completely replaced rules_docker.
However, some other use cases such as container_run_and*\* rules have no equivalent.
You might still decide to use rules_docker, and perhaps even volunteer to help maintain it.
You can find a migration guide at https://docs.aspect.build/guides/rules_oci_migration.
See the install instructions on the release notes: https://github.com/bazel-contrib/rules_oci/releases
To use a commit rather than a release, you can point at any SHA of the repo.
With bzlmod, you can use archive_override or git_override. For WORKSPACE, you modify the http_archive call; for example to use commit abc123 with a WORKSPACE file:
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v0.1.0/rules_oci-v0.1.0.tar.gz"
with a GitHub-provided source archive like url = "https://github.com/bazel-contrib/rules_oci/archive/abc123.tar.gz"strip_prefix = "rules_oci-0.1.0" with strip_prefix = "rules_oci-abc123"sha256. The easiest way to do this is to comment out the line, then Bazel will
print a message with the correct value.Note that GitHub source archives don't have a strong guarantee on the sha256 stability, see https://github.blog/2023-02-21-update-on-the-future-stability-of-source-code-archives-and-hashes
rules_oci does not contain language-specific rules, but we do have limited documentation on how to accomplish typical tasks.
[!NOTE] Your language not listed above? Please contribute engineering resources or financially through our Sponsor link!
There are some generic examples of usage in the examples folder.
Note that these examples rely on the setup code in the /WORKSPACE file in the root of this repo.
oci_image into a container daemon. Can optionally produce a loadable tarball.curl in some cases.oci_image or oci_image_index to a remote registry.[!WARNING]
Signing images is a developer preview, not part of public API yet.
oci_image using cosign binary at a remote registry.oci_image at a remote registry using cosign.(top 30 of 110)
Starlark
83.5%
Shell
15.3%
Go
1.1%