Reputation: 253
I'm running a php-fpm wordpress container.
The wordpress source files are mounted in a named volume "wordpress" shared with the Nginx container.
Everything is running well except when i need to update wordpress to a new version. The code inside the named volume persists. It is normal for a named volume...
I could manually delete the volume but there must be a better way.
My dockerfile:
FROM wordpress:4.9.5-php5.6-fpm-alpine
My docker-compose.yml
version: '3.1'
services:
php:
build: ./docker/php/
restart: unless-stopped
volumes:
- wordpress:/var/www/html
- ./web/wp-content/:/var/www/html/wp-content/
- ./web/wp-config.php:/var/www/html/wp-config.php
environment:
- DEBUG=${DEBUG:-0}
- MYSQL_USER=$MYSQL_USER
- MYSQL_PASSWORD=$MYSQL_PASSWORD
- MYSQL_DATABASE=$MYSQL_DATABASE
nginx:
image: nginx:1-alpine
restart: unless-stopped
expose:
- 80
volumes:
- wordpress:/var/www/html
- ./web/wp-content/:/var/www/html/wp-content/
- ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx/wordpress.conf:/etc/nginx/wordpress.conf
environment:
- VIRTUAL_HOST=localhost
mysql:
image: mysql:5.6
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
- MYSQL_USER=$MYSQL_USER
- MYSQL_PASSWORD=$MYSQL_PASSWORD
- MYSQL_DATABASE=$MYSQL_DATABASE
volumes:
- mysql:/var/lib/mysql
volumes:
wordpress: {}
mysql: {}
networks:
default:
external:
name: wordpress
Looking forward to reading your suggestions
Thank you
Upvotes: 14
Views: 22862
Reputation: 1100
When wordpress image is updated the image will not update wordpress itself but the php version. As wordpress can be updated via wp-admin and that is the recommended way to update wordpress even in docker setup. You can refer this github discussion where it is explained. The answer which explained it.
Upvotes: 2
Reputation: 344
It’s easier solution.
You have to edit wp-config.php file by add define('FS_METHOD','direct'); to the end of file. Save the file and run update. From now, you don’t need FTP server to update your WordPress. Remember! Before update make a backup
Upvotes: 1
Reputation: 1098
It's easier solution.
You have to edit wp-config.php
file by add define('FS_METHOD','direct');
to the end of file.
Save the file and run update. From now, you don't need FTP server to update your WordPress.
Remember! Before update make a backup :)
Upvotes: 4
Reputation: 5088
My answer applied to the official docker wordpress image. So probably off topic but might help someone.
If you are using docker-compose
you can pull the latest image using this command.
docker pull wordpress
I believe this will update your core docker image. Any other local project which you docker-compose up -d
with this yml image setting as this will use the latest update.
services:
wordpress:
image: wordpress:latest
If you currently running the image will you need to docker-compose down
and docker-compose up -d
to invoke the update.
Upvotes: 1
Reputation: 157
To expend on @Bigbenny's answer, my Dockerfile looked like the following:
FROM wordpress:latest
WORKDIR /var/www/html
COPY . /var/www/html
COPY check-wordpress-version.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/check-wordpress-version.sh
ENTRYPOINT ["/usr/local/bin/check-wordpress-version.sh"]
Two things to notice here:
chmod 755
the file or I would get a permissions denied error/usr/local/bin
because for some reason when I would just use ENTRYPOINT["check-wordpress-version.sh"]
, the file wouldn't be found by the container.I also, slightly tweaked the script to look like:
#!/bin/sh
VOLUME_VERSION="$(php -r 'require('"'"'/var/www/html/wp-includes/version.php'"'"'); echo $wp_version;')"
echo "Volume version : "$VOLUME_VERSION
echo "WordPress version : "$WORDPRESS_VERSION
if [ $VOLUME_VERSION != $WORDPRESS_VERSION ]; then
echo "Forcing WordPress code update..."
rm -f /var/www/html/index.php
rm -f /var/www/html/wp-includes/version.php
fi
docker-entrypoint.sh apache2-foreground
For my use-case, I had to use apache2-foreground
rather than php-fpm
; I also deleted the /var/www/html/wp-includes/version.php
file.
Finally, in my docker-compose, instead of the using the image
directive; I used build: ./wordpress
.
I hope this helps!😁
Upvotes: 1
Reputation: 1466
Wordpress seems to have addressed this under this issue.
I notice you are using a custom wp-config.php
. Most likely, you can use the WORDPRESS_CONFIG_EXTRA
for this rather than mounting wp-config.php
.
Theoretically (per the link above), updating the image should update the database, but I have not confirmed.
Based on this, my stack.yml
/docker-compose.yml
looks like this:
environment:
WORDPRESS_CONFIG_EXTRA: |
define( 'AUTOMATIC_UPDATER_DISABLED', true );
volumes:
- "./themes:/var/www/html/wp-content/themes/"
- "./plugins:/var/www/html/wp-content/plugins/"
- "./uploads:/var/www/html/wp-content/uploads/"
Upvotes: 6
Reputation: 253
Thank you for your help. It worked. Here is the code i'm using.
I overriden the entrypoint in dockerfile
COPY check-wordpress-version.sh /usr/local/bin/
ENTRYPOINT ["check-wordpress-version.sh"]
Here is the content of check-wordpress-version.sh to check wordpress current version.
VOLUME_VERSION="$(php -r 'require('"'"'/var/www/html/wp-includes/version.php'"'"'); echo $wp_version;')"
echo "Volume version : "$VOLUME_VERSION
echo "WordPress version : "$WORDPRESS_VERSION
if [ $VOLUME_VERSION != $WORDPRESS_VERSION ]; then
echo "Forcing WordPress code update..."
rm -f /var/www/html/index.php
fi
docker-entrypoint.sh php-fpm
Upvotes: 6
Reputation: 1008
When the wordpress container comes up it checks for the existence of files at /var/www/html
and copies only if not present. So in your case may you can update the entrypoint
script to check the wordpress version in the wp-includes/version.php
in the /var/www/html
and the files in the container and then make a decision to replace the new files.
Edit:
According to this just deletion of index.php
or wp-includes/version.php
should copy the files from container again. Or may you can update your entrypoint
script to copy files to /var/www/html
all the time, but that may cause issues if you choose to scale the wordpress
layer.
Upvotes: 7