Running ibm-mobilefirst-starter container locally

Disclaimer: The solution discussed herein is from my own personal experience as a developer using the MobileFirst platform and do not represent IBM's view nor IBM's interest in supporting this officially.

If you have tried an evaluation of MobileFirst Platform Foundation using the ibm-mobilefirst-starter image on IBM Bluemix, you might have wondered:

  • How do I run the container locally on my computer?
  • How do I add and run my own projects?

The purpose of this blog is to provide answers to these questions.

Before you begin

When running the ibm-mobilefirst-starter image, you created a Docker container that was instantiated from the image. To run the container locally, complete the following steps:

  1. Install Docker.
  2. Install Cloud Foundry CLI and the Cloud Foundry plugin for IBM Containers. Follow the instructions here.

Pull the image from the IBM Containers registry:

  1. Open the terminal.
  2. Login to the Bluemix and to the IBM Container Service / Registry to access the image. Detailed instructions here.
cf login
cf ic login
  1. Pull the image.
docker pull registry.ng.bluemix.net/ibm-mobilefirst-starter

Note: The terminal referred to in this blog is the Docker terminal i.e., if you’re using Docker Toolbox, the Docker Quickstart Terminal.

Run the image

To run the image locally, run the following command from the terminal. Ensure the username and password for logging into the MobileFirst Operations console / MobileFirst Analytics console are provided within the command.

docker run -d -p 9080:9080 -e MFPF_ADMIN_USERNAME=<username> -e MFPF_ADMIN_PASSWORD=<password> registry.ng.bluemix.net/ibm-mobilefirst-starter

Run the image with your projects

To add your own project(s) and optionally remove the MobileFirstStarter sample project, complete the following steps:

  1. Create a directory on your machine with a name of your choice.
  2. Create a Dockerfile (file named Dockerfile) in the directory and add the following to the Dockerfile.
FROM registry.ng.bluemix.net/ibm-mobilefirst-starter:latest
  1. Add your project to the directory (For example, HelloMFP.war)
  2. Create an XML file using the same project name (for example, HelloMFP.xml), and add the following code snippet (modified with the correct project name):

Contents of HelloMFP.xml

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
    <application context-root="/HelloMFP" id="HelloMFP" location="HelloMFP.war" name="HelloMFP" type="war">
        <classloader delegation="parentLast">
            <privateLibrary id="worklightlib_HelloMFP">
                <fileset dir="${shared.resource.dir}" includes="worklight-jee-library.jar"/>.
                <fileset dir="${wlp.install.dir}/lib" includes="com.ibm.ws.crypto.passwordutil*.jar"/>
            </privateLibrary>
        </classloader>
    </application>
    <!-- Declare the IBM MobileFirst Server database. -->
    <dataSource jndiName="HelloMFP/jdbc/WorklightDS" transactional="false">
        <jdbcDriver libraryRef="DerbyLib"/>
        <properties.derby.embedded createDatabase="create" databaseName="${shared.resource.dir}/derbyDB/HelloMFP/WRKLGHT" user="WORKLIGHT"/>
    </dataSource>
    <!-- Define any other IBM MobileFirst Server properties here -->
    <jndiEntry value="false" jndiName="HelloMFP/mfp.session.independent"/>
    <jndiEntry value="httpsession" jndiName="HelloMFP/mfp.attrStore.type"/>
 </server>
  1. Add the following to the Dockerfile created in (2). Ensure to replace the ‘HelloMFP’ with the name of your project.
1
2
COPY HelloMFP.xml /opt/ibm/wlp/usr/servers/defaultServer/configDropins/overrides/
COPY HelloMFP.war /opt/ibm/wlp/usr/servers/defaultServer/apps/

Note: Repeat steps (3), (4) and (5) for every project you want to add to the image.

  1. If you wish to remove the MobileFirstStarter project, add the following to the Dockerfile created in (2).
1
2
RUN rm /opt/ibm/wlp/usr/servers/defaultServer/configDropins/overrides/MobileFirstStarter.xml
RUN rm /opt/ibm/wlp/usr/servers/defaultServer/apps/MobileFirstStarter.war
  1. Build the image with the new Dockerfile. Ensure you run the command from within the directory created in (1) and specify the name of the tag for tagging the image in the command.
docker build -t <name of the tag>
  1. Run the image using the following command (modified with your username and password for the MobileFirst Operations Console / MobileFirst Analytics Console and the correct tag name).
docker run -d -p 9080:9080 -e MFPF_ADMIN_USERNAME=<username> -e MFPF_ADMIN_PASSWORD=<password> <name of the tag>
Last modified on May 01, 2016
Share this post: