Using Docker compose to develop plugins – Part 2

In this, the second part of the series showing a docker compose based development environment for wordpress, we look the rest of the files in the system and the commands which are run to complete the install and configuration of the site. A reminder that the first part of the series, which covered the Docker file and docker compose file is available here.

Additional files

The additional files which are referenced in the Dockerfile and the docker compose file, are used to run the site install, the plugin install and if applicable the site import. There is also a wrapper script which makes the install commands run as user www-data rather than as root1.

The first script is the simple wrapper script wp-sh.sh.

This is fairly easy to understand – it just takes any parameters passed to it and wraps it round a sudo -u www-data so the command runs as the apache user.

The install-wordpress.sh command runs the famous wordpress 5 minute install and looks like this:

Again it’s pretty obvious what is happening here but this file will need to be changed so that it has the settings you want for your site.

Finally the install plugins command file install-plugins.sh has this basic content:

This file will need to be altered to add the individual plugins your site needs. I’ve just put some example plugins which I tend to use for my projects, but you can put any you need instead.

There is one other optional step which is covered by a script called import-wordpress.sh. You would use this if you are setting up a development version of an existing site and want to import some content. In that case you would export the site as an xml file and place it in the files directory with the name site-content.wordpress.xml. You could also create an export of the menu structure you use and place that in a file called site-menu.xml. If you have those files then this is what goes in the import-wordpress.sh script:

Final Setup

With these files in place, and the plugin you are developing installed in the plugin/myplugin directory there are a few commands we need to run to get the site up.

First, so make sure the permissions are correct we do the following:

This will make sure that the shell scripts which do the wordpress etc install are executable and also that the db and www directories are writable. Obviously you would change the user name to be your login name.

With this set you can run:

and assuming everything is ok you should see

If you don’t get this, there will be an error message which should show what went wrong.

Once the containers are running the wordpress site is available but there are still some steps to do. First you need to add a local hosts entry which maps the domain you have called your development site (in this case wordpress.localhost) to the local machine ip. This is normally as simple as adding  127.0.0.1 wordpress.localhost  into your local hosts file.

Then, to complete the install process run

Each of these will carry out their tasks to set up the site, install the plugins and if applicable import some content. Once these sites are complete the new wordpress site will be available at http://wordpress.localhost. You can login to it with the user and password you set in the install-wordpress.sh script.

In the final part of this series, I’ll go through setting up debugging so that you can really start plugin development.

  1. If the scripts ran as root they would mess up the permissions and the site wouldn’t work properly

Leave a Reply