In order to configure a Wordpress Multisite setup I have been using docker bind mounts to inject a custom .htaccess file into a container.
docker compose file fragment:
volumes:
- type: bind
source: /opt/custom_htaccess
target: /var/www/html/.htaccess
Due to moving the .htaccess file to the Dockerfile a new problem arises when starting the service. It is not able to start because the .htaccess untar process fails.
wordpress_multisite.llaz7a57a6id@vps01 | tar: ./.htaccess: Cannot open: File exists
wordpress_multisite.llaz7a57a6id@vps01 | tar: Exiting with failure status due to previous errors
I prefer to use default Wordpress images, so I am wondering what would be the best solution.
Experiencing the same issue. Wouldn't it be an option to use the --skip-old-files option for tar here? See https://www.gnu.org/software/tar/manual/html_node/Dealing-with-Old-Files.html
For now I'm working around this with
RUN rm -f /usr/src/wordpress/.htaccess
in my Dockerfile (since I've been using my own with the wordpress image as base image anyway).
This way, there won't be a .htaccess in the tar archive that would conflict with the bind-mounted one.
The entrypoint copies WordPress from /usr/src/wordpress/ to /var/www/html/. You could overwrite the /usr/src/wordpress/.htaccess so it gets copied over
The entrypoint copies WordPress from
/usr/src/wordpress/to/var/www/html/. You could overwrite the/usr/src/wordpress/.htaccessso it gets copied over
Thanks for this suggestion. Indeed this could be a solution to get my multisite setup running initially. But in practise the .htaccess file is modified by plugins during runtime. I want to persist those changes as well. The only practical way to get this done is to have the .htaccess file bind mounted and editable. Therefore the proposed solution will not work completely as intended.
I'm a little confused why you want to persist changes to .htaccess but not to the rest of the WordPress install? (Which will also complicate WordPress automated updates, which are highly recommended for the security of your deployment.)
I'm a little confused why you want to persist changes to
.htaccessbut not to the rest of the WordPress install? (Which will also complicate WordPress automated updates, which are highly recommended for the security of your deployment.)
You are completely right. Of course I am also persisting the wp-content folder to disk so I can easily update my wordpress containers using new images without loosing current content. So basically my requirement is to be able to persist the dynamic parts of my wordpress installation and config.
I'm facing the same problem. I'm using a docker config file to store .htaccess and mount it into the container, otherwise I just persist the wp-content folder on a volume. This recent change does not allow that, because startup fails.
Couldn't we just modify docker-entrypoint.sh to skip .htaccess if it already exists (just with other folders during tar extract)?
Yeah, I think making .htaccess a new special case is the more conservative solution.
I'm running into the same issue. I was previously using tag 5.5.3-apache, and my switch to 5.6.0-apache failed with similar errors that lfleuren described. My situation is similar in that I have a custom persisted .htaccess and wp-content folder. The custom .htaccess file is to support some security plugins I use as well as SSL redirects since my site is behind a load balancer (in a Kubernetes cluster)
I'm using a COPY of a .htaccess in my Dockerfile. This works in FROM wordpress:5.5-php7.4-apache but not in FROM wordpress:5-php7.4-apache (which is now 5.6). Now my htaccess is overwritten by the default wp htaccess
@laurenskling Just put this into your Dockerfile:
RUN rm -f /usr/src/wordpress/.htaccess
I changed the COPY from /var/www/html/.htaccess to /usr/src/wordpress/.htaccess and now it works again :) thanks for the help
I'm facing the same problem. I'm using a docker config file to store
.htaccessand mount it into the container, otherwise I just persist thewp-contentfolder on a volume. This recent change does not allow that, because startup fails.Couldn't we just modify
docker-entrypoint.shto skip.htaccessif it already exists (just with other folders during tar extract)?
This would be my proposed solution as well. It leaves room for use of a custom .htaccess and in case not provided fall back to the default configuration. I am still in need of a solution because I believe using default docker images is the prefered way to go in most situations. Are there any arguments against this solution?
I'm facing the same issue here. Since all of our local development follows the path of using the default image, persisting the wp in a docker volume but keeping the customizable part flexible (e.g. multi-site install) this totally breaks our development workflow right now. Modifying docker-entrypoint.sh to skip .htaccess would be the preferred way here.
Has anyone had success with the latest changes? I pulled 5.7.0-apache and it's still giving the same errors. I confirmed that the image pulled was the latest version that was created 2 days ago
docker-pullable://wordpress@sha256:2f85b64e373aa340300adde9925f42dd041b4494337bc940fb98b46e650c4451
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress 5.7.0-apache 6f6ff186d9ca 2 days ago 551MB
Here's the log from the Kubernetes container
WordPress not found in /var/www/html - copying now...
WARNING: /var/www/html is not empty! (copying anyhow)
WARNING: '/var/www/html/wp-content/plugins/akismet' exists! (not copying the WordPress version)
WARNING: '/var/www/html/wp-content/themes/twentynineteen' exists! (not copying the WordPress version)
WARNING: '/var/www/html/wp-content/themes/twentytwenty' exists! (not copying the WordPress version)
WARNING: '/var/www/html/wp-content/themes/twentytwentyone' exists! (not copying the WordPress version)
tar: ./.htaccess: Cannot open: File exists
tar: Exiting with failure status due to previous errors
I have these mounts and the .htaccess is still giving troubles
Mounts:
/var/www/html/.htaccess from wordpress-configmap (rw,path="htaccess")
/var/www/html/wp-content from wordpress-persistent-storage (rw)
Doh, nope, there's a bit I missed in #589 :facepalm:
New PR up at https://github.com/docker-library/wordpress/pull/600
Most helpful comment
I'm facing the same problem. I'm using a docker config file to store
.htaccessand mount it into the container, otherwise I just persist thewp-contentfolder on a volume. This recent change does not allow that, because startup fails.Couldn't we just modify
docker-entrypoint.shto skip.htaccessif it already exists (just with other folders during tar extract)?