WordPress on IBM Containers Update

Back in May 2015, Miguel showed us all how to deploy WordPress on Bluemix using containers. Now you can use the official WordPress image from the Docker Hub instead of the custom image used in the previous tutorial!


How?

This tutorial assumes you have already installed docker, the cf cli, and the cf “ic” plugin. For instructions on how to install these, please refer to the bluemix docs.

Step 0: Log into Bluemix and target your desired space

Step 1: Copy the official WordPress image to your IBM Containers Registry

As described in the Bluemix docs, “cpi” will automatically “Access a Docker Hub image or an image from your local registry and copy it to your private Bluemix repository.”

Step 2: Create the volume that will serve as the WordPress file system

You can name the volume whatever you want but remember the name for when you run the container in step 4.

Step 3: Create Services

For this tutorial we are going to use the “ClearDB MySQL Database” service as well as the “Sendgrid” service that was in the optional portion of the previous tutorial. To create instances of these services using the CLI you would run:

Refer to the Bluemix catalog for a comprehensive list of available services.

Step 4: Run the Container with the WordPress Image

IBM Bluemix offers a consistent development model across its 3 compute options (cloud foundry, containers, and virtual machines) by allowing users to bind services to their application, container, or virtual machine.

The credentials for interacting with the service are injected into your application/container/VM via a special environment variable named VCAP_SERVICES.

In the case of containers, the service will also flatten the JSON structure of this environment variable as follows:

These are some example credentials as they would appear on the IBM Bluemix console.

This is how the same credentials would appear after being flattened.

To run the official WordPress image on IBM containers, we can map these VCAP_SERVICES environment variables to the ones expected by the image as part of our run command:

If you are working from a Windows machine you must run the command from the

Docker Quickstart Terminal.

Specifically, this command sets each WORDPRESS variable to the name of the corresponding VCAP_SERVICES variable, then passes a command which evaluates these assignments on the container before running the image’s normal entrypoint.

note:Make sure to replace [VOLUME], [NAMESPACE], [CLEARDB_SERVICE_INSTANCE], and [SENDGRID_SERVICE_INSTANCE] with their respective values.

Step 5: Requesting and Binding an IP

Check on the status of your new container:

Pay special attention to the PORTS column. We want it to contain your desired IP and port. If it is missing an IP, then you will need to request a new one (or unbind an existing one) and bind it.
To print your current list of IPs, run:

To request a new IP (free trial accounts are currently limited to 2):

To bind it to your container:

After binding the IP to the container you will access WordPress by typing the bound IP into your browser.

Setting up email in your WordPress Container (optional):

The container does not have an SMTP server configuration and so the WordPress email functionality will not work. We can use the SendGrid plugin to remedy this. In step 3 we bound a SendGrid service instance to our container. Now it is just a matter of installing the plugin and setting credentials.

Step 1. Install the SendGrid plugin in your WordPress instance.

The plugin can be installed in the wordpress ui (Plugins > AddNew > Search (Sendgrid))
Once it is installed, make sure to activate it.
8c

Step 2. Set Credentials

Go to Plugins > Installed Plugins > SendGrid Settings
8d

To fill out the username and password, you will need to print the credentials that were created when you bound this service instance to your container. To accomplish the binding and unbinding of service instances to a container, IBM Containers uses the Cloud Foundry Service Keys feature that was contributed in the summer of 2015.

While normally the credentials are injected into your running container, sometimes it is easier to just print the credentials and copy/paste them to the corresponding fields. To obtain the SendGrid username and password, you must first find the corresponding service key by running:

Once you find the service key associated with your running container (the container name should be in the key), you can retrieve the SendGrid credentials:

Fill in the Username and Password fields from the service key credentials and proceed to configure your own mail settings. You can try sending a test email from the same page. If the email is sent properly, then your WordPress installation is complete!


If you want to know more about the jStart team please visit our site, and talk to us more from our contact page.

Luke Stack

Luke joined IBM’s jStart team as a co-op in January 2016 . Luke is a junior, pursuing Bachelor’s of Science degrees in both Computer Science and Mathematics at Appalachian State University.

Luke Stack
Luke Stack
Luke Stack