Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating wordpress plugins inside a docker container

Here is my scenario:

I have been developing a plugin which will be modified very often, I need to create an image using docker in which install a fresh version of wordpress and then import all the database and plugins from the development environment, ( The plug in is on github)

I managed to install wordpress on docker using https://github.com/eugeneware/docker-wordpress-nginx

Now here are my questions:

1-is there any way to modify the wordpress files and folders after it's been installed in docker(for installing plugins and using command line, not the wordpress GUI)

2-If I want to achieve what I explained above what is the best workflow?

like image 462
Mohammad Avatar asked Apr 20 '14 09:04

Mohammad


People also ask

Is there a docker entry point for WordPress?

This article is the continuation of WordPress with Docker, AWS (ECS, Code Pipeline, Load Balancer, RDS, EFS) Complete Series. For better understating, please start from the beginning of the series. Our WordPress Docker image ( wordpress:latest) already contains an entry point. which is called docker-entrypoint.sh.

How to access WordPress_DB_name from a container?

The WORDPRESS_DB_NAME needs to already exist on the given MySQL server; it will not be created by the wordpress container. If you'd like to be able to access the instance from the host without the container's IP, standard port mappings can be used: Then, access it via http://localhost:8080 or http://host-ip:8080 in a browser.

How to keep your dockerfile up-to-date?

Additionally, the wordpress Dockerfile has an example of doing this. The following Docker Hub features can help with the task of keeping your dependent images up-to-date: Automated Builds let Docker Hub automatically build your Dockerfile each time you push changes to it. Include pre-installed themes / plugins

How do I install a WordPress theme or plugin?

Mount the volume containing your themes or plugins to the proper directory; and then apply them through the "wp-admin" UI. Ensure read/write/execute permissions are in place for the user: Themes go in a subdirectory in /var/www/html/wp-content/themes/


2 Answers

Two possible answers to your problem. I'm struggling with this right now as well, so YMMV.

First, if you're running the Docker container on your host, you can always pause it docker pause, create a new image from the running container docker commit, then push it to a private repository docker push (a live Wordpress install is probably not appropriate for the public Docker Hub). Once that's done, you can resume the container docker unpause and then you can go update the image on your dev system. Then come back once the upgrade is in and tested and all is good, and then docker pull the image and restart your service so it uses the new image.

Not a great solution, but it will work.

Based on the comment by Tadeusz, I wouldn't necessarily run your whole WP install from a data volume. They are volatile and if, for any reason, your container gets deleted and it's the only one referencing the data volume, then you lose everything (unless you keep multiple backups -- you do keep multiple backups, right?)

The other solution I'm considering is having plugin changes be deployed as part of the Dockerfile. A much more deliberate approach, but can be webhooked such that it automatically builds a new Docker image when you commit to your Github repo. There's discussion of doing that automatic build process here. The server admin end of things on your end hosting will need to pull a the new image as I mentioned above. And done.

Of course, setting this up is left as an exercise for your dev system.

Cheers!

like image 69
WineSoaked Avatar answered Sep 19 '22 15:09

WineSoaked


Late to the party but I've got a decent solution to this. It isn't covered by the other answers and should also be useful to future readers.

I'm comfortably running this on an ec2 t2-micro box and so far it's worked perfectly. Wordpress, mySQL and Nginx are all installed in their own containers (via Docker compose) and Docker volumes are used to maintain both mySQL and Wordpress state. Code and additional info about the Nginx setup taken from here.

docker-compose.yml:

version: '3.6'

 services:
    db:
      image: mysql:5.7
      volumes:
        - db_data:/var/lib/mysql
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: db_root_pass
        MYSQL_DATABASE: db
        MYSQL_USER: db_user
        MYSQL_PASSWORD: db_pass
    nginx:
      depends_on:
        - wordpress
      image: nginx:latest
      restart: always
      ports:
        - "80:80"
      volumes:
        - ./nginx.conf:/etc/nginx/nginx.conf
    wordpress:
      depends_on:
        - db
      volumes:
        - wp_data:/var/www/html/wp-content
      image: wordpress:latest
      restart: always
      environment:
        WORDPRESS_DB_HOST: db:3306
        WORDPRESS_DB_USER: db_user
        WORDPRESS_DB_PASSWORD: db_pass
 volumes:
    db_data:
    wp_data:

the db_data volume is mapped to the mySQL data directory within the mySQL container and the wp_data volume is mapped to the Wordpress content directory in the Wordpress container. What you can do is configure the CLI to write to the wp_data directory on the host and those changes will be revealed on the Wordpress site without needing to rebuild any containers!

like image 41
HJCee Avatar answered Sep 17 '22 15:09

HJCee