Updating wordpress plugins inside a docker container
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!
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!