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
2
Answers
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:
Here you can find more information about initContainer
Another option is rebuild the image with the right permissions.