3

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 by www-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...


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))?

Community
  • 1
  • 1
That Brazilian Guy
  • 3,328
  • 5
  • 31
  • 49

1 Answers1

-2

you can set owner using ADD or COPY command in dockerfile, for your COPY command, try COPY --chown:www-data:www-data ./ /var/www/html/wp-content/themes/theme/.

EMC
  • 1,560
  • 2
  • 17
  • 31
  • I'm *already* doing that. It doesn't work. That's exactly the very issue I'm having. – That Brazilian Guy Apr 12 '19 at 20:22
  • if you declare it as a volume _before_ doing copy --chown, it won't work, if you reverse the order of operations it should. I can't tell what order you're doing them in here. – EMC Apr 12 '19 at 20:29
  • I don't declare volumes on my dockerfile, it's only those two lines from the question, nothing else. The `wordpress` image declares a volume in its dockerfile, though. My image is derived from it -- in fact my image exists only to copy a folder into the WordPress image. – That Brazilian Guy Apr 12 '19 at 20:32
  • Try redeclaring it after the copy step, same as base image. – EMC Apr 12 '19 at 20:34
  • No luck, unfortunately :( – That Brazilian Guy Apr 12 '19 at 20:37