-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make already existing files owned by current user #474
Make already existing files owned by current user #474
Conversation
We used to do this, and it was reverted intentionally (#74) because it causes massive issues for folks who are doing things like local development of WordPress themes / plugins. Now that we can run as an arbitrary user, perhaps that can be reconsidered (and we'd then instead recommend that development users run as their own UID instead, thus avoiding the problem). |
Thank you @tianon for looking at my PR. From what I see, the PR you mentioned (#74) actually ensures that files in the The goal of this PR is to make sure that existing files in Having the Plus I think that the rule of checking whether the If needed I can expose more the issues that I encountered when I have the |
Just as a side note, I would add that changing the file permissions inside the container changes them also on the host, which can make file manipulation on the host harder to manage. |
Thanks @michaelperrin does this fix the "installing plugin failed : cannot write to directory " issue that I face when running 5-fpm ? |
@freechelmi Just to be sure, do you install plugins via WP-CLI or the web interface? And which folders do you share between the host and the container? In either case, that should fix the issue. I can make the test for you if you wish. |
@michaelperrin : Yes Web interface , and we mount wp-content , see our dc |
hey @michaelperrin I've been struggling with this particular issue for a really really long time. I develop a WordPress plugin and I really need a solid docker solution so that I can start reliably adding e2e tests into my testing workflows. I'd like to try this solution out but I can't figure out how to run your image locally to see if this works. Any recommendations on how I can try this PR out to see if it helps my situation? |
Hi @thomasplevy ! Just stumpled over your comment as I have subscribed this thread - waiting for a solution, too. I have workaround'd this - I think it is not a workaround, more a possible solution: Put an additional script after you run your WordPress container, as you can see here: It allows you to run E2E tests without any problem in your CI: https://gitlab.com/devowlio/wp-reactjs-starter/-/jobs/492094866 Perhaps you are interested in our open source boilerplate: WP React Starter |
@matzeeable oh man thank you so much. This is a really simple and elegant solution! |
Is there any update of this PR? Is it going to be accepted or not. This is causing few questions on SO. |
To any one going through the same problem, create a new image for production, but dont FROM wordpress:5.4.1-apache
COPY --chown=www-data:www-data ./src /usr/src/wordpress/wp-content/themes/foo_theme
EXPOSE 80 443 This way, when the However, if doing things this way, you volumes:
- wordress:/var/www/html If you do this, your plugin wont update, because it will use the version that is on the volume. |
This PR makes all already existing files in the
/var/www/html
directory owned by thewww-data
user instead ofroot
.Issue description
It is a problem that has been mentioned several times here on GitHub (see #436 and #358) and on StackOverflow.
The problem happens for example when sharing a folder into the wp-content WordPress folder, like in this Docker Compose example:
Running these commands:
Will result in a list like:
The wp-content (which has been created by Docker when sharing the volumes) folder belongs to the
root
user instead of thewww-data
user.Why the issue is happening
Docker creates the shared folder before WordPress is installed into the
/var/www/html
folder.The
docker-entrypoint.sh
script is executed after and checks whether the/var/www/html
folder already exists, and if so, fixes user ownership of it:The test is not relevant anymore. Since PHP 7.x, the Docker images create a
/var/www/html
folder that already belongs towww-data
, meaning that the condition will never be met. You can check this by running this:Result:
Same command for PHP 5.6:
Result:
Changes made
The following changes were made:
/var/www/html
root ownership.