January 9, 2017 | Written by: Vinod Singh
Share this post:
In our discussions with customers, there is always an area of interest in movement of Docker container workloads from on premise to Cloud Service Providers (CSP). Customers are looking to move to the public cloud to leverage the advantage of agility, auto scaling, life cycle management and the ability to pay as you go. Customers want to burst the edge and move towards cloud to reduce the IT cost and take advantages of pick load requirements.
Not long ago, one of our customers had a Java application running on one of the CSPs and wanted to move to another CSP using a container. Therefore, we needed to provide solutions to the customer for the smooth transition of these container workloads across multiple CSPs including on premise. Our enterprise customers have realized the advantage of containers in flexibility to build once and move applications without the need to rewrite or redeploy their code. Containers make it easier for customers to deliver production applications across their hybrid environments.
Almost all cloud providers have Docker container services – IBM Bluemix container Service, AWS EC2 container service, Azure container service, Google container service and so on.
Here I will take a simple example of a Java Cloudant Web Starter application from IBM Bluemix public catalog. The application will be deployed first as a Cloud Foundry runtime application on Bluemix and then source code will be downloaded to the local machine. Next, Docker image will be created using the same source code and run as Docker container on a local machine. The Docker image is like an executable file to run an application on Windows/Unix machines. It has a file system and parameters to use at runtime. It doesn’t have state and never changes. A container is a running instance of an image. The same Docker image will be pushed to IBM Bluemix Containers and the application will be deployed as container. Finally, the same Docker image will be pulled at AWS from IBM Bluemix and run as a Docker container on AWS.
Figure 1, Docker Image across local machine, IBM Bluemix and AWS
Figure 1 shows, at a high level, how the ‘javacloudant_dockerimage’ is created in a local host machine, and then pushed to the IBM Bluemix Container registry. The application runs as Docker container ‘bluemixcontainer’ on Bluemix. The image can then be pulled to AWS and where a ‘awscontainer’ is created to run the application.
This will ensure that the user will get the same experience of Java Cloudant Web Starter application whether it is running on premise (local host), Bluemix Container, or AWS. Basically, the application runs on all locations as Docker container and uses the same Docker image (javacloudant_dockerimage).
Figure 2, Cloudant DB connected with all CSP’s containers
It is important to note that the application running at all three locations must share the same Cloudant database running on Bluemix public as depicted in Figure 2 above.
To achieve the same experience across these three environments, we must do the following:
- 1.Deploy and run Java Cloudant webstarter on Bluemix public as a Cloud Foundry App
- 2.Run the Java Cloudant application as Docker container on local machine
- 3.Run the Java Cloudant application on IBM Bluemix Containers
- 4. Run the Java Cloudant application on Amazon Web Services
1. Deploy and run Java Cloudant webstarter on Bluemix public as Cloud Foundry App
The prerequisite is to have signed up for IBM Bluemix (Public) and have an ID to log in with.
In IBM Bluemix console, select Catalog, then Boilerplates in left pane of screen.
Select the Java Cloudant Webstarter and follow the steps on the screen as shown below in Figure 3.
Figure 3, Configuration to use in the Java Cloudant Webstarter boilerplate
After you have entered your application name, click Create. This will create your application with Java runtime and a Cloudant database.
Your application can be accessed at appname.mybluemix.net, where appname is the name of your application, as shown in Figure 4.
Figure 4, Static welcome page for the application we just launched
Now you can add documents using the application console. The added document will appear in the application deployed as container on local host, IBM Bluemix as well as AWS.
- The uploaded documents can be verified in Cloudant ‘Launch’ console.
2. Local Host: Run the Java Cloudant application as Docker container
Before running Docker container on local host, following prerequisites are required to proceed:.
- Install git client installed locally
- Install Docker locally on your machine. This will give you access to the Docker command-line tools
- Install the IBM Bluemix command-line tools, which will require installing the prerequisite Cloud Foundry command line tools
- I used OS X to implement this tutorial, although you can easily adapt into other platformsThe JavaCloudant application .jar file with server.xml from step 1 are pushed to GitHub. Also, the Dockerfile required to create the Docker image is included. The following steps are required to run JavaCloudant as Docker container on localhost machine:
A. Download the code from GitHub from your host console:
git clone https://github.com/vksinghibm/bluemixcontainermovement.git
Three files will be downloaded:
Dockerfile JavaCloudantApp.war server.xml
The Docker file contains the command to download the IBM liberty image. Copy the .jar and .xml file and expose port 9080. Then start the default liberty server.
COPY JavaCloudantApp.war /config/apps/
COPY server.xml /config/
CMD ["/opt/ibm/wlp/bin/server", "run", "defaultServer"]
B. Create the Docker image:
$ docker build –t \
Before running the Docker container, let us set the VCAP_SERVICES environmental variable for Cloudant credentials. Access the Java Cloudant app dashboard on Bluemix and go to ‘Runtime’ on the left pane. Then click ‘Environmental Variables’ and copy on top right as shown in Figure 5 below. This will copy the VCAP_SERVICES credentials in your local clipboard.
Note: Ensure you add single quote (‘) before actual pasting the content and then close with (‘).
Figure 5, Page to copy the environmental variable of the application
C. Now, run the Docker container
$ docker run --name localcontainer -d --env VCAP_SERVICES -p \
Open the browser to access localcontainer as appears in Figure 6 – http://localhost:9080/
Figure 6, Same static webpage of application as appeared earlier in Figure 4
3. Bluemix: Run JavaCloudant application as Bluemix container service
Next we will deploy the JavaCloudant application as container on Bluemix.
The same Docker image created on local host will be used.
A. First, install the Bluemix plugins on local machine and then push the image to Bluemix public
$docker push registry.ng.bluemix.net/vksingh/javacloudant_dockerimage
Verify that images are uploaded to Bluemix registry
$cf ic images | grep “javacloudant_dockerimage”
B. Create the container using Bluemix dashboard, click Catalog, then select Containers
There, select javacloudant_dockerimage. Populate with these sample configurations:
|Public IP address:
||Request and Bind Public IP
||CCS_BIND_APP “Cloud Foundry Application Name”
||CCS_BIND_SRV “Bluemix container name”
Figure 7, these are the sample configuration to use
After updating configuration as shown in Figure 7, click Create.
C. The Bluemix container will be up and running after a few minutes and note a public IP as shown in Figure 8 below:
Figure 8, Container dashboard to access the public IP address
D. Access the URL as http://ipaddrress:9080, where ipaddress is the address show above under Public IP
Figure 9, Static page of JavaCloudant application running on Bluemix but same as Figure 4 & 6.
So, you have successfully deployed JavaCloudant application as a container on local host and IBM Bluemix. You have seen the consistent behavior of the application across different platforms in hybrid environment. Try to delete or upload a single file from any one of application (local host) and can see the deleted or uploaded file in other application (Bluemix) automatically.
In my next blog, I will describe how to move the container to AWS, to achieve a uniform experience across three environments of local host, Bluemix and AWS.
Any questions or comments, please contact me Twitter