How can I define an owner to an empty_dir using container_image or container_layer from bazel rules_docker? How can I define an owner to an empty_dir using container_image or container_layer from bazel rules_docker? kubernetes kubernetes

How can I define an owner to an empty_dir using container_image or container_layer from bazel rules_docker?


In a BUILD file, the attribute you're looking for is ownername. See the pkg_tar reference documentation documentation for more details. Also, I don't think you can pass it directly to container_image, you have to create a separate pkg_tar first. Like this:

pkg_tar(    name = "with_empty_dirs_tar",    empty_dirs = [        "etc",        "foo",        "bar",    ],    ownername = "nginx.nginx",)container_image(    name = "with_empty_dirs",    tars = [":with_empty_dirs_tar"],)

In general, container_image has a subset of pkg_tar as direct attributes to make simple forms of adding files, but for complex use cases you should create a pkg_tar yourself for full access to all of its features for adding/arranging files and setting their ownership.

The names you see in that PR is a variable in a Python helper tool which the BUILD file rules use as part of the implementation. There's a layer of abstraction between what you write in a BUILD file and that Python code.