WordPress on IBM Containers Update

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

Update – March 31, 2016: Thanks to a commenter, we noticed that we were mounting the volume below at the wrong path (/wp-content rather than /var/www/html). This means that WordPress updates, installations, and user uploads would be lost in the event of a container shutdown.

Unfortunately, after mapping the volume to the proper path, we found that the WordPress entrypoint script errors while trying to change the ownership of the WordPress files within the mounted volume. These errors are related to a limitation with the platform’s use of NFS and, until this issue can be resolved, users must override the official WordPress entrypoint script.

To provide an example, we have updated the ibmjstart/bluemix-wordpress image using this approach. To run the image on the IBM Bluemix Container service, simply perform the following steps from the cf ic command line plugin (optionally replacing the parameters with your own preferred names):

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 which can be instantiated directly from the cf cli via

Optionally, if you would like to configure email notification for your site, you may wish to create an instance of the “SendGrid” service:

Refer to the Bluemix catalog for a comprehensive list of services and plan options.

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 wordpress image does not include an SMTP server and so the built-in WordPress email functionality will not work without an external service. If you have created and bound a SendGrid instance in the previous section, it is now just a matter of installing the corresponding plugin and setting the 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.

Share: Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditEmail this to someonePrint this 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

Latest posts by Luke Stack (see all)

21 comments

  • Pingback: Wordpress on Bluemix Containers - IBM Emerging Technologies Blog

  • Baker

    Can you provide a workaround for in Step 4 for Windows users? Is it possible to add the VCAP_services env variables via the UI?

    • We have recently updated the article to address this issue. The current run command in step 4 should now also work on Windows as long as you run it from the Docker Quickstart Terminal.

  • Farhan

    I followed your article and the mapped the IBM container volume to /wp-content in cf ic run … command as mentioned in the above command. However, the wordpress container is using /var/www/htmal/wp-content folder for the contents.

    I tried to map the container volume to /var/www/html/wp-content but then the container failed to start wordpress. Looking at the container logs it turned out that wordpress is trying to change the ownership of the /var/www/html/wp-content folder which is mapped to container volume and getting failed.

    Please advise how can I change or map the /var/www/html/wp-content folder to container’r volume

    • Farhan, thank you for pointing out this oversight. We meant to keep the volume mounted at the same path as the original post (/var/www/html), but it looks like this is no longer working with the latest WordPress image. I’ve added an update to the top of the post with some advice on how you can work around this limitation, but unfortunately I think it means that we’ll need to continue wrapping the official image with our own Dockerfile in order to run it on IBM Containers at this time.

  • Simeon Petkov

    The line

    cf ic run -p 80 -v myVolume:/var/www/html -e CCS_BIND_SRV=wp-cleardb registry.ng.bluemix.net/myNamespace/bluemix-wordpress

    results in

    docker: Error parsing reference: “myVolume:/var/www/html” is not a valid repository/tag.

    • Simeon, this is the error you would receive if you missed the ‘-v’ flag, causing it to interpret your volume as the image tag. Please double-check you have properly entered the command.

      -Luke

      • Simeon Petkov

        I copy & paste it as you see it above.

      • Søren Skov

        I’m getting the same error-message as above from the command as written in the article

        (cf ic run -p 80 -v myVolume:/var/www/html -e CCS_BIND_SRV=wp-cleardb registry.ng.bluemix.net/myNamespace/bluemix-wordpress)

        with appropriate names substituted and used on eu-gb.

        Currently I’m having a hard time getting any of the guides for using wordpress on bluemix to work.

    • Actually, we started seeing this error as well now. Looks like it is actually caused by a change to the cf cli that was introduced with version 6.17 — the cli now eats the “-v” option instead of passing it to the plugin: https://github.com/cloudfoundry/cli/issues/825

      To work around the issue, simply use --volume instead of -v. I’ve also gone ahead and updated the post at the top of the blog entry with this change.

  • Simeon Petkov

    And how can I change php.ini contents with the container set-up?

    Asking because of: The uploaded file exceeds the upload_max_filesize directive in php.ini

    Not sure how to change the file contents in the image …

  • Dileep Sharma

    Successfully executed all the steps but when I try to open the IP address which is bound to the container it doesn’t open. Can you please help.

  • Pingback: So.. we’re on bluemix – To the blogmobile…

Leave a Reply

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