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.
securityContext:
runAsUser: 0
command: ["/bin/sh"]
args:
- -c
- |
chown -R www-data:www-data /var/www/html/pub/media
chown -R www-data:www-data /var/www/html/pub/static
When I run kubectl -n magento exec magento-web-dweq34672 -- ls -al var/www/html/pub
I see static directory still under root ownership. everytime I Am manually changing it using following which is getting frustrating now, any suggestions
kubectl -n magento exec magento-web-dweq34672 -- chown -R www-data:www-data var/www/html/pub
Init container is what you need here, use init container to change the permissions and the ownership.
As suggested before you can use initContainer
in your deployment spec.
Example:
initContainers:
- name: my-init
image: busybox:1.28
command: [ 'sh', '-c', 'chown -R www-data:www-data var/www/html/pub']
Here you can find more information about initContainer
Another option is rebuild the image with the right permissions.