<p>I am trying to change ownership of static directory in a container but for some reason it's not working but it works on another directory.</p>
<pre><code>securityContext:
  runAsUser: 0
command: [&quot;/bin/sh&quot;]
args:
- -c
- |
  chown -R www-data:www-data /var/www/html/pub/media
  chown -R www-data:www-data /var/www/html/pub/static
</code></pre>
<p>When I run <code>kubectl -n magento exec magento-web-dweq34672 -- ls -al var/www/html/pub</code> I see static directory still under root ownership. everytime I Am manually changing it using following which is getting frustrating now, any suggestions</p>
<p><code>kubectl -n magento exec magento-web-dweq34672 -- chown -R www-data:www-data var/www/html/pub</code></p>

<p>As suggested before you can use <code>initContainer</code> in your deployment spec.</p>
<p>Example:</p>
<pre><code>initContainers:
        - name: my-init
          image: busybox:1.28
          command: [ 'sh', '-c', 'chown -R www-data:www-data var/www/html/pub']
</code></pre>
<p><a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">Here</a> you can find more information about initContainer</p>
<p>Another option is rebuild the image with the right permissions.</p>
