Skip to main content
Version: 1.2.x

Serving Static Content

This is useful for creating an image to serve static content, such as the output of building your frontend javascript.

In this example we'll use the docker nginx image, but you could use any other static content webserver the same way.


Pull our base image.


load("@rules_oci//oci:pull.bzl", "oci_pull")
name = "nginx_debian_slim",
digest = "sha256:6b06964cdbbc517102ce5e0cef95152f3c6a7ef703e4057cb574539de91f72e6",
image = "",

Next lets create our static content files.


<!DOCTYPE html>

<h1>Our Homepage</h1>

<p>Hello from index.html</p>



This is text file.

And finally the build rules for our image.


load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
name = "static",
srcs = ["index.html", "textfile.txt"],

name = "static_tar",
srcs = [":static"],
package_dir = "/usr/share/nginx/html"

name = "frontend_image",
base = "@nginx_debian_slim",
tars = [
# Intentionally omit cmd/entrypoint to default to the base nginx container's cmd/entrypoint.
# entrypoint = [],
# cmd = [],
name = "frontend_tarball",
image = ":frontend_image",
repo_tags = ["ourfrontend:latest"],

If you want to customize the nginx.conf you could create ./frontend/nginx.conf and add this to ./frontend/BUILD.

name = "nginx_conf_tar",
srcs = [":nginx.conf"],
package_dir = "/etc/nginx",

# ...
tars = [
# ...

Try running the container with docker

bazel run :frontend_tarball
docker run --rm -p 8080:80 "ourfrontend:latest"

Wait for nginx to start in your container, and then go to localhost:8080 and localhost:8080/example.txt to see your static content.