WordPress on Bluemix Containers
An update to this blog was posted on January 26, 2016.
A guide to Using app binding to connect a WordPress instance to a database.
Docker Containers are ideal for hosting WordPress sites for three reasons: official images, Volumes, and scalability.
- The Official WordPress Image: WordPress maintains the WordPress docker image on docker hub. This is an official image so you can be sure it is stable and set up properly.
- Docker Volumes: Volumes are used as persistent file storage. We use volumes as a file system for WordPress. If you stop, restart or even delete your wordpress container the volume will persist. This allows us to save media and install plugins/themes directly to the volume. Using volumes also makes migrating and scaling your WordPress site very easy!
- Scalability: With Bluemix docker containers you can increase the Memory of your containers, and Number of CPU’s. You can also create a cluster of identical containers to host your site. This is great for load balancing! We also have the added benefit of being able to scale the database services independently. Your WordPress Database can come from any of the MySQL services in the Bluemix catalog. (this tutorial will use clearDB)
This tutorial assumes you have already installed the cf “ic” plugin and docker CLI. For instructions on how to install the CLIs see the bluemix docs. The first three steps are done with docker and the cf ic clis.
Step 1: Pull the official image locally
$ docker pull ibmjstart/bluemix-wordpress
Step 2: Tag the wordpress image for pushing up to your bluemix registry
you’ll need to replace [namespace] with your namespace.
$ docker tag ibmjstart/bluemix-wordpress registry.ng.bluemix.net/[namespace]/wordpress
Step 3: Push [namespace]/wordpress up to your registry
$ docker push registry.ng.bluemix.net/[namespace]/wordpress
note: you may need to use “cf ic login” before pushing up to your bluemix registry.
Step 4: Create the volume that will serve as the WordPress file system
$ cf ic volume create [Volume Name]
You can name the volume whatever you want but remember the name for when you run the container in step 6.
Step 5: Create a MySQL Service
Lets head over to Bluemix for the rest of the tutorial. In bluemix, you will need to create a new app to bind a MySQL DB to. I recommend using the SDK for node.js runtime from the catalog.
Go ahead and create it:
Make sure to choose a unique name for your app. Once your app is running go ahead and create a MySQL Service instance in the catalog:
Finally make sure to bind it to the node.js app we just created. This is done in the App section.
Step 6: Run the Container with the WordPress Image
Go on to your Dashboard and select Start Containers:
Next you will see this (your wordpress image should be listed):
Click on the wordpress image. That will take you to the following page. there a quite a few details on this page that we need to get right.
- Make sure you are under the scalable group tab (Important!)
- Give your container group a unique name
- choose mybluemix.net as the route domain.
- choose as many instances as you would like (1 should be fine)
- choose a unique hostname
- open HTTP port 80 (very important)
- Click advanced options
- Select the volume you created in step 4 from the dropdown. Set the mount path to “/var/www/html”
- Bind the bridge app we made in step 5. by selecting the bridge app from the dropdown.
The rest can be left as default.
Step 7: Hello WordPress
visit your page using the [Hostname].mybluemix.net url you selected in step 5 (note: this may take a few minutes to deploy, so give it a while). Your page should look like this:
You should now have a fully functional WordPress install on containers! run through the setup and you will be good to go. If you would like to learn more about how our WordPress image works, you can read about it HERE
Setting up email in your WordPress Container (optional):
The container does not have a SMTP server configuration so the WordPress email functionality will not work. We can use the SendGrid plugin to remedy this.
Step 0: Create a SendGrid service in bluemix. Bind it to your MyDB application.
SendGrid can be found in the catalog. This is what your app’s dashboard will look like when you have successfully bound your SendGrid service instance.
Step 1. Install the SendGrid plugin in your WordPress instance.
Step 2. Set Credentials
The credentials can be found back on your dashboard. From this screen (Click “Show Credentials” under SendGrid logo)
Fill out all the info and Save. You can try sending a test email on that same page. If the email sends properly, then your WordPress install is complete!