I'm having a folder ownership issue when I try to run WordPress on Docker containers. Folders like wp-content
and themes
are owned by root, not allowing me to install themes and plugins from the web interface.
Goals
- Run WordPress on Docker.
- Obtain a theme from a git repo (owned by us).
- Be able to run WP-CLI from its official Docker image (
wordpress:cli
). - Be able to install themes and plugins from the web interface.
- Have all files and folders under
/var/www/html
be owned bywww-data
(uid 33).
Specs
- Docker version 18.09.5, build e8ff056
- docker-compose version 1.24.0, build 0aa59064
- single container instances for each service - no kubernetes, swarm, stack, etc.
- My
docker-compose.yml
- My
dockerfile
(copied from the git repo):
FROM wordpress:5
COPY --chown=33 ./ /var/www/html/wp-content/themes/theme/
Volumes
I don't declare volumes on my dockerfile -- it's only those two lines above, nothing else. In fact, this image exists only to copy a folder into the WordPress image. The WordPress image (which my image derives from) declares a volume in its dockerfile, though.
I do declare volumes on my docker-compose file but when omitting them the issue persists
Results
File and folder ownerships...
- when using a custom image with named volumes
- when using a custom image without named volumes
- when using the default image with named volumes
- when using the default without named volumes
UPDATE
There's some issue going on with the COPY
step on the Docker build, but I can't figure out what.
I changed my dockerfile
to
FROM alpine
COPY ./ /var/www/html/wp-content/themes/theme/
RUN chown -R 33:33 /var/www/html
RUN ls -n /var/www/html
If I build from alpine, uid 33
is the owner:
Step 4/4 : RUN ls -n /var/www/html
---> Running in e9850fa85800
total 4
drwxr-xr-x 1 33 33 4096 Apr 12 19:34 wp-content
I change the first line to FROM wordpress
, now root
is the owner:
Step 4/4 : RUN ls -n /var/www/html
---> Running in 2810cc37aaba
total 4
drwxr-xr-x. 3 0 0 4096 Apr 12 19:38 wp-content
How do I proceed to obtain the results that I want (that is, the theme files on /var/www/html/wp-content/themes/theme/
and all files and folders owned by www-data
(uid 33))?