DEV Community

Thomas Südbröcker
Thomas Südbröcker

Posted on

Run a Docker image as a Cloud Foundry App on IBM Cloud

In that blog post I want to point out an awesome topic: “Run a Docker container image as a Cloud Foundry App on IBM Cloud”

Rainer Hochecker, Simon Moser and I had an interesting exchange about running a Docker image as a Cloud Foundry App on IBM Cloud.

The advantage with that approach is: you don’t need to instantiate a Kubernetes or OpenShift cluster. You can just run a single Docker image with your single application on IBM Cloud. That can be useful in different situations where you need to control the contents of your application, and the cloud foundry build-pack mechanism maybe restricts you.

IBM offers to run Cloud Foundry Apps on IBM Cloud and supports a set of build packs. But, by the fact IBM uses Cloud Foundry, you can also upload a Docker image as a Cloud Foundry application, it’s an officially supported feature. Yes there is no documentation related to that topic in the IBM Cloud documentation, but you can apply the Cloud Foundry documentation.

By the fact IBM uses , you can also try to upload a Docker image as a Cloud Foundry application, currenlty there is no restriction, but it's not offically supported. You not will find any documentation for that on IBM Cloud, but as IBM Cloud uses Cloud Foundry you can apply topics from the Cloud Foundry documentation.

One impact of that situation is, you don’t see the VCAP variables and you can’t use the out of the box binding for IBM Cloud services. You have to manage the bindings to your IBM Cloud services by yourself.

LET’S START WITH A SHORT GUIDE: HOW TO SETUP A CLOUD FOUNDRY APPLICATION USING A DOCKER IMAGE

When you follow the steps, you need to replace the name for the domain, port or hostname with your own settings. We will use in that example the [IBM Cloud Shell(https://cloud.ibm.com/docs/cloud-shell?topic=cloud-shell-getting-started)] on IBM Cloud and Node-RED as our Docker image.

The following images shows a simplified overview.

  1. We push the Docker image and run it as a container in a Cloud Foundry app
  2. We define a route with a port mapping to access the application from the internet.


STEP 1: LOGON TO IBM CLOUD AND OPEN THE IBM CLOUD SHELL.

The gif shows how to access the IBM Cloud Shell from the IBM Cloud UI.

STEP 2: CHANGE TO THE IBM CLOUD UI TO CREATE A CLOUD FOUNDRY SPACE IN YOUR REGION, IF YOU DON’T HAVE ONE.

The gif shows how to create a new space dev, in the existing organization thomas.suedbroecker , in the region Germany.


STEP 3: GO BACK TO THE IBM CLOUD SHELL AND SET THE CLOUD FOUNDRY ENDPOINT, ORGANIZATION AND SPACE. I MY CASE I USED FOLLOWING VALUES.

  • Endpoint: api.eu-de.cf.cloud.ibm.com
  • Organization: thomas.suedbroecker
  • Space: dev
  • Resource group: Default
ibmcloud target --cf-api api.eu-de.cf.cloud.ibm.com -o thomas.suedbroecker -s dev -g Default
Enter fullscreen mode Exit fullscreen mode

STEP 4: VERIFY YOUR CLOUD FOUNDRY SETTINGS ON IBM CLOUD (IBM CLOUD DOCUMENTATION)

ibmcloud target
Enter fullscreen mode Exit fullscreen mode

STEP 5: PUSH A DOCKER IMAGE FROM A CONTAINER REGISTRY.

  • Name: node-red
  • Image: node-red-docker:v10

In the IBM Cloud Shell you need to install the Cloud Foundry API with ibmcloud cf install and verify the API version ibmcloud cf -v.

ibmcloud cf push node-red --docker-image=docker.io/nodered/node-red-docker:v10  --no-start --no-route
Enter fullscreen mode Exit fullscreen mode

Note: Of course you can also use a private container image registry like the IBM Cloud Image Container Registry , if you want.

In this case, you’d need understand the Cloud Foundry documentation:

CF_DOCKER_PASSWORD=YOUR-PASSWORD cf push APP-NAME --docker-image REPO/IMAGE:TAG --docker-username USER
Enter fullscreen mode Exit fullscreen mode

The IBM Cloud Image Container Registry also contains the documentation how to do this for Cloud Foundry, here is the command.

export CF_DOCKER_PASSWORD=<apikey>
ibmcloud cf push appname -o <region>.icr.io/<namespace>/<image_repo> --docker-username iamapikey
Enter fullscreen mode Exit fullscreen mode

STEP 6: GET THE GUID FROM THE CLOUD FOUNDRY APP INSTANCE. A_GUID=APPLICATION GUID

A_GUID=$(ibmcloud cf app node-red --guid|awk '/[0-9]/{print $1}')
echo $A_GUID
Enter fullscreen mode Exit fullscreen mode

STEP 7: SET THE PORT TO ACCESS THE APPLICATION INSIDE THE DOCKER CONTAINER OF THE CLOUD FOUNDRY APPLICATION.

The port information you get from the Docker image description.

  • PORT: 1880
ibmcloud cf curl /v2/apps/$A_GUID -X PUT -d '{"ports": [1880]}'
Enter fullscreen mode Exit fullscreen mode

STEP 8: IN THIS STEP WE CREATE A ROUTE TO THE CLOUD FOUNDRY APP, TO ACCESS LATER THE RUNNING APPLICATION FROM THE INTERNET.

The Domain name eu-de.mybluemix.net depends on the region you create the Cloud Foundry App. In that sample we using eu-de. (see IBM Cloud documentation )

  • Domain: eu-de.mybluemix.net
  • Hostname: node-red-tsuedbroecker
ibmcloud cf create-route dev eu-de.mybluemix.net --hostname node-red-tsuedbroecker
Enter fullscreen mode Exit fullscreen mode

STEP 9: WE NEED TO MAP THE ROUTE TO THE CLOUD FOUNDRY APP , TO ACCESS THE RUNNING APPLICATION FROM THE INTERNET.

  • Application name: node-red
  • Domain: eu-de.mybluemix.net
  • Hostname: node-red-tsuedbroecker
ibmcloud cf map-route node-red eu-de.mybluemix.net --hostname node-red-tsuedbroecker
Enter fullscreen mode Exit fullscreen mode
  1. Now we extract the GUID for the created route. (R_GUID=route GUID)
R_GUID=$(ibmcloud cf curl "/v2/routes?q=host:node-red-tsuedbroecker" | sed -n 's|.*"guid": "\([^"]*\)".*|\1|p')
echo $R_GUID
Enter fullscreen mode Exit fullscreen mode

STEP 10: NOW WE EXTRACT THE GUID FOR THE NEWLY CREATED ROUTE. (R_GUID=ROUTE GUID)

ibmcloud cf curl /v2/route_mappings -X POST -d '{"app_guid": "'"$A_GUID"'", "route_guid": "'"$R_GUID"'", "app_port": 1880}'
Enter fullscreen mode Exit fullscreen mode

STEP 11: WE NEED TO UPDATE THE ROUTE MAPPINGS WITH OUR GUID’S. (R_GUID AND A_GUID)

ibmcloud cf curl /v2/route_mappings -X POST -d '{"app_guid": "'"$A_GUID"'", "route_guid": "'"$R_GUID"'", "app_port": 1880}'
Enter fullscreen mode Exit fullscreen mode

STEP 12: START THE CLOUD FOUNDRY APPLICATION.

ibmcloud cf start node-red
Enter fullscreen mode Exit fullscreen mode

STEP 13: VISIT THE CLOUD FOUNDRY APP IN THE IBM CLOUD UI AND INSPECT THE POSSIBILITIES.

In the gif you see, there is no build pack information and there are no environment variables.


STEP 14: NOW OPEN THE APPLICATION URL AND USE THE RUNNING NODE-RED INSTANCE.

The gif shows, how to access the application URL inside the Cloud Foundry App.

I hope this was useful for you and let’s see what’s next?

Greetings,

Thomas

Top comments (0)