How to update wordpress on docker

后端 未结 5 544
再見小時候
再見小時候 2021-02-06 07:36

I\'m running a php-fpm wordpress container.

The wordpress source files are mounted in a named volume "wordpress" shared with the Nginx container.

Everyth

5条回答
  •  生来不讨喜
    2021-02-06 08:37

    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:

    1. I had to chmod 755 the file or I would get a permissions denied error
    2. I placed the script inside the /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!

提交回复
热议问题