<p>From the <a href="https://github.com/bazelbuild/rules_docker/pull/310/files" rel="nofollow noreferrer">PR</a> that implemented empty_dirs, it seems there's support for defining dir owners (with the names argument) and mode into the add_empty_dir method of TarFile class.</p>
<p>But the container_image rule (and container_layer) supports only mode.</p>
<p>This works:</p>
<pre><code>container_image(
    name = &quot;with_empty_dirs&quot;,
    empty_dirs = [
        &quot;etc&quot;,
        &quot;foo&quot;,
        &quot;bar&quot;,
    ],
    mode = &quot;0o777&quot;,
)
</code></pre>
<p>But this returns an error: &quot;ERROR: (...) no such attribute 'names' in 'container_image_' rule&quot;:</p>
<pre><code>container_image(
    name = &quot;with_empty_dirs&quot;,
    empty_dirs = [
        &quot;etc&quot;,
        &quot;foo&quot;,
        &quot;bar&quot;,
    ],
    names = &quot;nginx&quot;,
)
</code></pre>
<p>Do we need to “<a href="https://github.com/bazelbuild/rules_docker/blob/master/docs/container.md#imageimplementation" rel="nofollow noreferrer">write a customized container_image</a>” if we want to add support for owner of empty_dirs?</p>

<p>In a BUILD file, the attribute you're looking for is <code>ownername</code>. See the <a href="https://github.com/bazelbuild/rules_pkg/blob/main/pkg/docs/reference.md#pkg_tar" rel="nofollow noreferrer">pkg_tar reference documentation</a> documentation for more details. Also, I don't think you can pass it directly to <code>container_image</code>, you have to create a separate <code>pkg_tar</code> first. Like this:</p>
<pre class="lang-py prettyprint-override"><code>pkg_tar(
    name = &quot;with_empty_dirs_tar&quot;,
    empty_dirs = [
        &quot;etc&quot;,
        &quot;foo&quot;,
        &quot;bar&quot;,
    ],
    ownername = &quot;nginx.nginx&quot;,
)

container_image(
    name = &quot;with_empty_dirs&quot;,
    tars = [&quot;:with_empty_dirs_tar&quot;],
)
</code></pre>
<p>In general, <code>container_image</code> has a subset of <code>pkg_tar</code> as direct attributes to make simple forms of adding files, but for complex use cases you should create a <code>pkg_tar</code> yourself for full access to all of its features for adding/arranging files and setting their ownership.</p>
<p>The <code>names</code> 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.</p>
