I struggled to build an image which would copy custom themes and plugins to /var/www/html/wp-content yet still retain www-data ownership for these files. I think this was due to the VOLUME in your image.
I was successful with the following.
FROM wordpress
COPY ["wordpress","/usr/src/wordpress"]
RUN chown -R www-data:www-data /usr/src/wordpress/*
Is this the best way to complete this or should I be approaching it differently?
bkc
You should do this in the entrypoint. That's where the image is actually installing data to /var/www/html.
@lazyfrosch The entrypoint copies files from /usr/src/wordpress to /var/www/html, so what @bkcummins is doing is the right way to do it.
That being said, I would probably COPY just the plugins and themes into the right directories in /usr/src/wordpress/wp-content instead of overwriting the entire /usr/src/wordpress directory.
great...thx for the feedback guys.
@md5 yes, but a volume should be touched in the entrypoint, and not in Dockerfile. Or it might now work when mounting in that volume...
@lazyfrosch The entrypoint already copies from /usr/src/wordpress into the volume on startup if it doesn't find an existing WordPress installation in a mounted volume. See here: https://github.com/docker-library/wordpress/blob/2877506644eec86186d32e5aac19d6737f113efa/apache/docker-entrypoint.sh#L44
What's been said is definitely correct IMO -- if you want to create a "production" version of the wordpress image with your plugins/themes pre-installed, them placing them in the appropriate place within /usr/src/wordpress is correct.
I'd note also that bind-mounting into /var/www/html directly for _development_ (as I've described over in https://github.com/docker-library/wordpress/issues/64#issuecomment-241145167) is also a pattern we've found to be reasonably effective. :+1:
I'm having a problem installing a plugin. I can see the directory is correctly copied to the /usr/src/wordpress directory, however it's not copied into the /var/www/html directory at any point.
Docker file:
FROM wordpress
COPY ["wp-subscribe","/usr/src/wordpress/wp-content/plugins/wp-subscribe"]
RUN chown -R www-data:www-data /usr/src/wordpress/wp-content/plugins/
Am I missing something?
@matanshukry, anything further in your Dockerfile? The entrypoint script will copy from /usr/src/wordpress/ to /var/www/html/, but only if the conditions match (see this part in the docker-entrypoint.sh). Another thing to check is if the volume used is empty; when using things like docker-compose it tries hard to ensure that volumes get reused from run to run so you often have to remove the container and all volumes (docker-compose rm -fv wordpress) but this can delete data like uploads if you have them.
I've been trying no end of variations of Dockerfiles to try get this to work for a production image. I have had no luck with the examples given here so I'm wondering if there has been other changes since.
Dockerfile is:
FROM wordpress:latest
COPY --chown=www-data:www-data ./src/plugins/ /usr/src/wordpress/wp-content/plugins/
COPY --chown=www-data:www-data ./src/themes/Divi/ /usr/src/wordpress/wp-content/themes/custom-theme/
COPY --chown=www-data:www-data ./src/uploads/ /usr/src/wordpress/wp-content/uploads/
COPY --chown=www-data:www-data ./src/fonts/ /usr/src/wordpress/wp-content/uploads/et-fonts/
Anyone also had any issues with this? Surely it should be easier to embed pre-loaded plugins and themes than it currently is... unless I'm going mad and missing something, which could be the case.
Is it still true that /usr/src/wordpress is copied to /var/www/html when the image is started? Can you point out where is that command in this repository?
Is it still true that /usr/src/wordpress is copied to /var/www/html when the image is started? Can you point out where is that command in this repository?
Yes:
Most helpful comment
@matanshukry, anything further in your Dockerfile? The entrypoint script will copy from
/usr/src/wordpress/to/var/www/html/, but only if the conditions match (see this part in the docker-entrypoint.sh). Another thing to check is if the volume used is empty; when using things likedocker-composeit tries hard to ensure that volumes get reused from run to run so you often have to remove the container and all volumes (docker-compose rm -fv wordpress) but this can delete data like uploads if you have them.