I use the command watch in my YAML file in order to sync my code on local computer to docker container.
However, every time a sync occurs, the docker container has the parent folder owner rewritten to root:root instead of www-data:www-data
Is there a command / switch to change, in order to make each sync from my local computer to container to use the user “www-data” (group “www-data” instead of root:root ?
It will use whatever is declared as last USER instruction.
Can you share your exact use case? Does this prevent the www-data user to be able to read the file? It shouldn’t hurt in an ephemeral container, unless something inside the container tries to modify the files you synched into the container.
To extend @meyay’s answer: Based on your previous posts and the “www-data” user, I assume you are syncing files into a PHP-FPM container. PHP containers by default run as root and PHP forks processes to run as www-data. So the USER will be root, even if the PHP process runs as non-root. As far as I remember, you can also run the main PHP process as non-root and you will just see a warning that PHP could not change the original user if the container user is not the same as configured in PHP.-FPM.
You could try changing the USER directive if you have a Dockerfile or add user: in compose
basically I have the following YAML to create a containers stack to locally develop a wordpress extension. In Visual Studio Code, everytime I change my local Wordpress Extension code, it sync the changes with docker container content, but the parent folder where the changed/synced file has its owner:ownergroup changed to root:root, instad of www-data:www-data
Try adding user: www-data:www-data to your wp service in the compose file. But if the entrypoint tries to run anything that requires root, it won’t work.
If that is the case, you could add a new service that just runs only for syncing the data to a common volume with the wp service. So both would mount the “wordpress” volume.