WordPress on Bluemix Containers

Share: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditEmail this to someonePrint this page

dockerPress
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.

Why?

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)

How?

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

Step 2: Tag the wordpress image for pushing up to your bluemix registry

you’ll need to replace [namespace] with your namespace.

Step 3: Push [namespace]/wordpress up to your registry

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

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.

5a

Go ahead and create it:

5b

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:

5c

Finally make sure to bind it to the node.js app we just created. This is done in the App section.

5d

 

Step 6: Run the Container with the WordPress Image

Go on to your Dashboard and select Start Containers:

Screen Shot 2015-07-06 at 12.31.36 PM

 

Next you will see this (your wordpress image should be listed):

Screen Shot 2015-07-06 at 12.33.14 PM

 

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.

  1. Make sure you are under the scalable group tab (Important!)
  2. Give your container group a unique name
  3. choose mybluemix.net as the route domain.
  4. choose as many instances as you would like (1 should be fine)
  5. choose a unique hostname
  6. open HTTP port 80 (very important)
  7. Click advanced options
  8. Select the volume you created in step 4 from the dropdown. Set the mount path to “/var/www/html”
  9. Bind the bridge app we made in step 5. by selecting the bridge app from the dropdown.

The rest can be left as default.

Screen Shot 2015-07-06 at 1.27.21 PM

hit create.

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:

7a

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.

0a

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

Once there go ahead and fill out the credentials.
8e

 

The credentials can be found back on your dashboard. From this screen (Click “Show Credentials” under SendGrid logo)

0a

 

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!

Share: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditEmail this to someonePrint this page
Miguel Clement

Miguel Clement

Miguel is a Computer Science Senior at Texas A&M Univeristy. He joined the jStart Emerging Technology Team in January 2015 and has been exploring the cutting edge ever since.
Miguel Clement
Miguel Clement

35 comments

  • Pingback: Accessing Bluemix Services In Containers - IBM Emerging Technologies

  • Jorge Flor

    Watch this error:
    MacBook-Pro-de-Jorge:BluemixWordpress jorgeflor$ docker pull ibmjstart/bluemix-wordpress
    Post http:///var/run/docker.sock/v1.19/images/create?fromImage=ibmjstart%2Fbluemix-wordpress%3Alatest: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
    MacBook-Pro-de-Jorge:BluemixWordpress jorgeflor$

    What can i do?

    • Miguel Clement

      Hi Jorge,
      this looks like an issue with your boot2docker vm. Try pulling another image, and I’m sure it will give the same error. The best solution I’ve found has been to restart the VM. this can be done by calling:

      “boot2docker down”
      (followed by)
      “boot2docker up”

      if any errors appear after “up” they should tell you more about what’s going on.

  • Morten Borklund

    Hi
    I followed your example, but I got en error when I tried to access my “wordpress-site” (step 7).

    Error establishing a database connection

    Any hint will do

    Best regards
    Morten

  • Miguel Clement

    There must be an issue with your clearDB connection. Here is how it should work:

    1. create an empty node app that will be used as a bridge between ClearDB and the container.
    2. bind a clearDB service to the bridge node app.
    3. go through the container image creation steps and when you get to this page: http://blog.ibmjstart.net/wp-content/uploads/2015/05/Screen-Shot-2015-07-06-at-1.27.21-PM.png Make sure that you selected the bridge application in the advanced options > service bindings dropdown, this is very important.

    If you are sure all of these things are set and configured properly and it still gives the error let me know an I will help you debug. Thank you for reading!

  • Murad Korejo

    Miguel,

    This is a great post! I was able to get WordPress running in a container in my Bluemix org, and I retrieved the DB creds from the Bluemix dashboard, but when I try to configure WordPress to use the DB (via the CF bridge application), I get a WordPress error which says:

    Sorry, but I can’t write the wp-config.php file.

    You can create the wp-config.php manually and paste the following text into it.

    Any ideas? Thanks again for the post regardless.

    • Murad Korejo

      Actually, I was able to get past the issue by launching the site in an incognito window. I have another question though and will post a comment for that.

  • Pingback: Hello world! | Head in the Cloud

  • Murad Korejo

    Miguel,

    I am trying to update the WordPress site in my container, but I’m not sure how. There is no FTP access to the site to my knowledge, and I can’t seem to be able to place new files on the persistent volume directly. Any thoughts?

  • Rene Meyer

    Hello Miguel,
    thank you for your tutorial. in your Dockerfile you referenced a version of WordPress Docker base image which was changed in the meantime in a way making your tutorial not working anymore.
    If you look on old revision of the WP Docker github project you see that many changes happened in the [docker]entrypoint.sh:
    https://github.com/docker-library/wordpress/tree/1420b4c44ba0cf13d2d1d1e41bbc3bc74e83ce9f/apache
    https://github.com/docker-library/wordpress/tree/master/apache
    I have now an example which works, including supervisor based ENTRYPOINT and ssh support:
    https://github.com/cloud-dach/wp-bluemix-container
    So I created a combination between the older revision of the base WP Dockerfile and your Dockerfile and scripts.

    • Thank you for bringing up the issue. We are looking into the problem to see if we can fix the tutorial.

      • Rene Meyer

        Hello Miguel,

        I had an issue in my Bluemix space, so there is nothing wrong with your tutorial. After I created a new space I can now repeat the tutorial each time without errors. The cf env of the bound application and MySQL service was not passed to the container, when I created container groups. This is now working. So I learned a lot about Docker and the Container service.
        Thank you very much for that tutorial.

  • Lee Surprenant

    The steps in the article worked for me with the existing ibmjstart/bluemix-wordpress image.
    Additionally, steps 1-3 can be simplified to the following one-liner by using the IBM Containers “cpi” command:

    cf ic cpi ibmjstart/bluemix-wordpress registry.ng.bluemix.net/[namespace]/wordpress

  • Alexio

    Hello,
    I’ve finished the tutorial and my WP is working fine (thanks!).
    Plugins to be installed often asks for the FTP access, but putting the URL of the WP installation is not working. What can I do?

    Thanks
    Alexio

  • Dai Hang

    Hello Miguel,
    Thanks ! This is a great post of binding IBM container and CF services. And in my project, we want to bind a CF runtime(like node.js) to a IBM container(like mongo) without assigning a public IP to the container.
    Is there any solution or guide for this requirement? Thanks in advance!

    • Lee Surprenant

      Dai, I don’t think you can do it at this time without assigning the Mongo container a public IP. You should be able to confirm it by trying to hit the container’s private IP from a bluemix app.

      Once you are able to connect to the Mongo container from a Bluemix app (e.g. by assigning it a public IP), you can register it as a service instance by following the documentation at https://www.ng.bluemix.net/docs/services/reqnsi.html#user_provide_services
      This decouples the mongo container from the application a little bit so that you can change one or the other without changing your code.

      • Dai Hang

        Thanks, Lee. Your suggestion is a good solution! We will test it and compare it to the pure containers solution(node.js container + mongo container). It seems your solution is more simple if depends cloud foundry deeply, and the pure containers solution more flexible(can deployed any docker-hosting platform) but harder learning curve and more maintain tasks.

  • Matteo

    Miguel,
    This is a great post!
    I have a question.
    How can i bind a Mongolab db to a container since the Mongolab service is no longer available on Bluemix?

    Best regards
    Matteo

  • Pingback: WordPress on IBM Containers Update - IBM Emerging Technologies Blog

  • Alex

    Hi and thanks for this nice tutorial !
    I would like to follow it until i get wordpress running but cf ic volume create XXX return an error :
    {
    “code”: “IC5000E”,
    “description”: “An issue occurred in IBM Containers. Contact Bluemix Support and reference this incident ID.”,
    “incident_id”: “2b79102d342a3eab”,
    “name”: “DefaultMessage”,
    “rc”: “500”,
    “type”: “General”
    }

    What does it mean?

  • Andres

    Hi,

    I would like to understand what I am doing… could you please clarify why you need to bind your blockstorage to an empty node.js app ? I understand it should be a kind of “Bridge”, so the BlockStorage can be created.. and once the Blockstorage is created is not longer needed and can be deleted… is that true ?

    • Lee Surprenant

      The bridge app is not needed for a “block storage” volume, but rather for binding certain bluemix services to the container. If you follow the updated post that is linked to from the top of this post, you will find that this bridge app is no longer needed for most of the services (including ClearDB and SendGrid).

  • Pingback: WordPress on IBM Containers Update - PyBloggers

  • Simeon Petkov

    My result:

    Difference from tutorial: hen creating the container the only choice that appears for a Service Binding is the DB service (ClearDb), not the bridge-app (Node). The app doesn’t show up in the drop-down (kind of makes sense, since the section is called Bind Service and not Bind Application).

    When creating it like this opening the container group URL results in a: 502 Bad Gateway: Registered endpoint failed to handle the request.

    The Node sample app opens fine. The DB service is bound to the app.

    Appreciating any comments!

Leave a Reply

Your email address will not be published. Required fields are marked *