Wordpress: can't copy into var/www/html

Created on 11 May 2016  路  13Comments  路  Source: docker-library/wordpress

my minimalist example:

FROM wordpress:latest

COPY . /var/www/html

This fails to run. The build succeeds but when I actually go into bash and look, the files are not there. If I instead COPY to /usr/src/wordpress, then it succeeds, but the contents of /var/www/html remain the same, so I'm not anywhere closer to my goal, since I assume that I need my files to be in the latter folder.

Thanks for any help.

Most helpful comment

Your custom theme needs to be uploaded into /usr/src/wordpress/wp-content/themes, which will be copied along with the rest of the WordPress source code at runtime over to /var/lib/www.

ie:

FROM wordpress

COPY . /usr/src/wordpress/wp-content/themes/my-theme

All 13 comments

This would be because /var/www/html is a VOLUME, since that's where we store the "mutable state" for WordPress. (/usr/src/wordpress gets copied over to /var/www/html on first run, and then the user is expected to manage WordPress updates in the standard "WordPress way" through either the web UI or via taking the newer tarball and extracting it manually)

See also https://github.com/docker-library/wordpress/blob/61dd78ce4fa9ccd592ead1edb379f209533b850c/apache/Dockerfile#L21 and https://github.com/docker-library/wordpress/blob/61dd78ce4fa9ccd592ead1edb379f209533b850c/apache/docker-entrypoint.sh#L22-L46.

I have a custom theme I need to upload to that directory though and I can't do so if the directory is read-only.

Your custom theme needs to be uploaded into /usr/src/wordpress/wp-content/themes, which will be copied along with the rest of the WordPress source code at runtime over to /var/lib/www.

ie:

FROM wordpress

COPY . /usr/src/wordpress/wp-content/themes/my-theme

What about wordpress plugins? Is there a way to have them installed automatically?

EDIT: nvm, I think we just need to copy them to /usr/src/wordpress/wp-content/plugins

Yeah, you're exactly right -- if you copy your plugins to /usr/src/wordpress/wp-content/plugins, they should be installed automatically after the container is initialized.

Hi! I think this is the proper place to ask about this. It's about a custom theme.
In my Dockerfile I copy wp-content into /usr/src/wordpress/wp-content (I've double checked that the theme is located inside the running containter), but it's not copied in /var/www/html.

The first time I run the container it worked, but now it complains it doesn't find the theme (which is right, as is not there).

I'd appreciate any hint, thanks in advance for your work and for sharing :)

@yamila-moreno if your goal is to bake a custom image which will install your theme alongside the WordPress install, then putting it in /usr/src/wordpress/wp-content is correct -- if you're looking for a local "theme development" solution, you should be able to simply bind-mount your theme directory into /var/www/html/wp-content appropriately and WordPress will be installed around it (and then you can restart/recreate the container at will and continue developing)

Hi @tianon thanks for your answer. I continued the troubleshooting and it was my mistake in the docker-file.yml. I was trying to ensure that the new content uploaded to the blog would persist if the container were stoped or removed, so I tried to map wp-content to my host (thinking in the uploads dir). It doesn't work! ^_^
Again thanks for your time :D

This is a hindrance to doing theme development since you'd have to restart your container every time you made a change. It would be nice to be able to declare the custom theme (or plugin, for that matter) as a volume so you can make changes on the host file system.

Doing so works after the initial run/copy, but it breaks if WP is not already installed in the container.

Disclaimer: I just started playing with Docker this week, so I could have it completely wrong.

@nalroff as I noted in my comment above (https://github.com/docker-library/wordpress/issues/146#issuecomment-278745084), for theme development, I usually just bind-mount my local theme directory directly into /var/www/html/wp-content so that it's automatically picked up by WordPress and I can update it live, refreshing to see the new content, something like:

$ docker run ... -v "$PWD":/var/www/html/wp-content/themes/my-cool-theme:ro ... wordpress

or via docker-compose.yml:

  volumes:
    - .:/var/www/html/wp-content/themes/my-cool-theme:ro

@tianon Interesting... this doesn't seem to work for me. The container cannot copy the wordpress files from /usr/src/wordpress into /var/www/html because /var/www/html/wp-content/themes/my-cool-theme already exists as a volume with my host machine's user as the owner using docker-compose.yml. I'd rather not adjust the permissions on my files to 777 or change groups or anything like that. What am I missing?

Again, I'm not hurting too bad about this... it works fine if I comment out my volumes, let the container start up once, and then uncomment them and re-up them. I have to repeat the process if I docker-compose down, of course.

Here is my docker-compose.yaml:

version: '2'
services:
  mysql:
    image: mysql:5.7
    environment:
    - MYSQL_ROOT_PASSWORD=password
    - MYSQL_DATABASE=somedb
  web:
    image: wordpress
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: somedb
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: password
    links:
    - mysql
    ports:
    - 127.0.0.3:8080:80
    volumes:
    - ./wp-content/themes/tpb-2017:/var/www/html/wp-content/themes/tpb-2017

Since the original question here is solved, I'm going to close.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.

@nalroff on your specific issue, I can't reproduce -- I've been using this method for theme development with this image for quite some time now (and was the main reason we switched from using rsync to using tar for copying the source into the volume back in https://github.com/docker-library/wordpress/pull/61#issuecomment-74555164)

my minimalist example:

FROM wordpress:latest

COPY . /var/www/html

This fails to run. The build succeeds but when I actually go into bash and look, the files are not there. If I instead COPY to /usr/src/wordpress, then it succeeds, but the contents of /var/www/html remain the same, so I'm not anywhere closer to my goal, since I assume that I need my files to be in the latter folder.

Thanks for any help.

FROM php:7.2-apache

WORKDIR /var/www/html/wordpress

Was this page helpful?
0 / 5 - 0 ratings