Bazel: rules_docker vs rules_oci

Posted on in programming

cover image for article

rules_docker and rules_oci are two Bazel rulesets that can be used to build Docker images and OCI images, respectively. Both rulesets have their own advantages and disadvantages, so it is important to choose the right one for your project.

rules_docker

rules_docker is the older of the two rulesets, and it is more mature and widely used. It provides a variety of features, including:

  • Support for building Docker images for a variety of platforms, including Linux, macOS, and Windows.
  • Support for building Docker images from a variety of sources, including source code, pre-built binaries, and Dockerfiles.
  • Support for pushing Docker images to registries, such as Docker Hub and Google Container Registry.

However, rules_docker also has some disadvantages:

  • It is not as flexible as rules_oci. For example, it cannot be used to build
  • OCI images for other container runtimes, such as Podman.
  • It is more complex to use than rules_oci.
  • It is not as well-maintained as rules_oci.

rules_oci

rules_oci is the newer of the two rulesets, and it is designed to be more flexible and extensible than rules_docker. It provides the following features:

  • Support for building OCI images for a variety of platforms, including Linux, macOS, and Windows.
  • Support for building OCI images from a variety of sources, including source code, pre-built binaries, and OCI image files.
  • Support for pushing OCI images to registries, such as Docker Hub and Google Container Registry.

In addition, rules_oci has the following advantages over rules_docker:

  • It is more flexible and extensible. For example, it can be used to build OCI images for other container runtimes, such as Podman.
  • It is easier to use than rules_docker.
  • It is better-maintained than rules_docker.

However, rules_oci also has some disadvantages:

  • It is not as widely used as rules_docker.
  • It does not support all of the features of rules_docker, such as the ability to build Docker images for Windows.

Which ruleset should you use?

If you need to build Docker images for a variety of platforms and you need support for all of the features of rules_docker, then you should use rules_docker. However, if you need to build OCI images for other container runtimes, or if you want to use a more flexible and extensible ruleset, then you should use rules_oci.

Here is a table that summarizes the key differences between rules_docker and rules_oci:

Feature rules_docker rules_oci
Supports building Docker images Yes Yes
Supports building OCI images No Yes
Supports building images for a variety of platforms Yes Yes
Supports building images from a variety of sources Yes Yes
Supports pushing images to registries Yes Yes
Flexible and extensible No Yes
Easy to use No Yes
Well-maintained No Yes

Slaptijack's Koding Kraken