The making of WordPress Docker Image

The next era of portability is called Docker. IMHO Old and new application should be developed keeping in mind the separation between application and data, and in my coaching experience WordPress is one of the application that must take this way. The building of a container image requires these points:

  1. keep in mind objective requirements of containers that must delivered by this image
  2. choose a good starting image
  3. define actions that must executed in 2 moments:
    1. In the container creation
    2. In the container execution
  4. define ports and volumes (this are the hands that will link container to the “external” word.

 

The container creations

Initial declarations:

Now it’s time to install the environment

Then define environment modules and add custom files (like the default apache configurations):

Finally install wordpress environment with wpcli and the last available version:

The image code ends with volume, ports definitions and the code to run at container startup:

Run on boot: wordpress.sh

The script on boot is doing this things:

  1. Check if wordpress installation is already present, otherwise it begins the auto-installation with wpcli
  2. Check if duplicator restore is present in the /var/www/backup dir, then if no wordpress installation will present, it simply move duplicator files into web root (/var/www/html)
  3. Executes mysql and apache (this is always done to run wordpress install or excecute powercli)

This is the code:

 

Usage

You could run this container specifying these parameters:

Param default value Note
WP_IPFDQN 127.0.0.1 You must change this value with an domain name
WP_TITLE wordpress Of course! change it with your app name
WP_ADMIN_USER admin
WP_ADMIN_PWD admin No extra comment! Must change it!
WP_ADMIN_EMAIL admin@email.tld Change it with your own mail

 

Simply create with

if you plan to restore from backup… or

to create a wp instance from scratch

   Send article as PDF