Docker Community Forums

Share and learn in the Docker community.

Updating Wordpress

I’ve used Brad Traversy’s YT video ‘Quick Wordpress Setup With Docker’ to get a WP up and running (see code below). But there is still a lot I don’t understand. I’ve got my WP site up and running but I’ve got WP telling me there are updates available, before I ask my main question, I’d like to clear something up.

I’ve got a local folder which is mapped to another folder in the container and they sync up. Am I right in assuming that if WP updates (via my WP Admin console http://localhost:8000/wp-admin), it’s actually updating my local folder, which in turn will update WP in the container since they are set up to sync with each other?

http://localhost:8000/ gives me access to the site.

Currently if I try to update this is what I see in the WP console

docker-compose.yaml ->

version: '3'

services: 

    #######  Database service  #######

    db:

        image: mysql:5.7

        volumes:

            # This gives us persistence

            - db_data:/var/lib/mysql

        # if the server reboots the container restarts

        restart: always

        # define your mysql environment variables

        environment:

            MYSQL_ROOT_PASSWORD: password

            MYSQL_DATABASE: wordpress

            MYSQL_USER: wordpress

            MYSQL_PASSWORD: wordpress

        networks:

            - wpsite

        

    #######  phpmyadmin service  #######

    phpmyadmin:

        depends_on: 

            - db

        image: phpmyadmin/phpmyadmin

        restart: always

        ports:

            - '8080:80'

        environment: 

            PMA_HOST: db

            # as above in the db service

            # your phymyadmin login is root/password

            MYSQL_ROOT_PASSWORD: password

        networks:

            - wpsite

    #######  Wordpress service  #######

    wordpress:

        depends_on:

            - db

        image: wordpress:latest

        ports:

            # local:8000, container:80

            - '8000:80'

        restart: always

        # okay so we want the WP install in the container to sync locally here

        # Mapping './' (local current folder) to '/var/www/html' (container's web root folder as we're using apache)

        volumes: ['./:/var/www/html']

        environment: 

            # the host is going to be the db service by mysql above, port 3306 is the default for mysql

            # we've already setup the DB user above

            WORDPRESS_DB_HOST: db:3306

            WORDPRESS_DB_USER: wordpress

            WORDPRESS_DB_PASSWORD: wordpress

        networks:

            - wpsite

            # map the volume of db_data (in service db above) and the network of 'wpsite'

networks: 

    wpsite:

volumes:

    db_data:

# Now go and run docker-compose up -d

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

Sorry I’m not sure how to use this. :thinking: I have very little experience of Linux/Unix command line and am completely new to the Docker paradigm. So if it helps you treat me like I’m your mother that way there are no assumptions :rofl:

Do I do this within the container’s shell?
COPY check-wordpress-version.sh /usr/local/bin/

What do I do with this line? Where exactly does this go?
ENTRYPOINT [“check-wordpress-version.sh”]

Here is the content of check-wordpress-version.sh to check wordpress current version.

So all of below is the content of file check-wordpress-version.sh you referenced above?

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

And the end result of all of this is what? That everytime I run MY WP container (in reference to my docker-compose.yaml) it automatically updates itself what about the plugins, etc?

Thanks for your help :smiley:

After watching countless videos I found an answer:

  • To update WP to a later version go into your yml file set the version you want.

  • Then just issue the following command:
    docker-compose up -d wordpress

  • Then go into your WP admin console and select ‘upgrade’

Simples