Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
akshaynayak02
Advisor
Advisor
This blog will help you to understand the basics of docker usage with Sap Cloud Platform cloud foundry.

You will create a docker image and will be deploying a Java application running on tomcat server inside a  docker container on your local machine .

Finally you will be deploying this application to SCP cloud foundry using Dockerhub as an intermediate layer.

 



 

STEP 1:

Make sure that docker is installed and running on your machine. Use the command docker -v



STEP 2:

Please download the Dockerfile and the helloworld java application (named ROOT.war) from

https://github.com/nayakkrec/helloworld



Your folder should have 2 files . Please don’t change the file names as there are dependencies.

  1. Dockerfile

  2. ROOT.war


STEP 3:

Use the below command to create a docker image based on the instructions from the Dockerfile with a tag “my_docker_image”. Don’t forget the  “.”  in the end.

docker build -t="my_docker_image" .



 

You can use the command docker images to find the docker images in your system as shown below.



At this moment, only the docker image is created from the docker file and the container is not running .Use the below command to confirm the same.

docker container ls



 

STEP 4:

Start docker container with port forwarding using the below command.

docker run -p 8080:8080 my_docker_image

Now, you will see that the container has started and the application is running on tomcat server inside the container.

In order to run the application, Open a browser(say chrome) and goto http://localhost:8080/

This is a simple helloworld app which displays date & time.



 

Use the command docker container ls to find the list of containers running in your system.



You can stop the container if needed using the below command from another terminal.

docker stop 93f1bbd5d52f          (i.e docker stop container_id)



Step 5.

In the previous steps (1 to 4) , you built a docker image from a docker file and then created a docker container and finally deployed a java application on tomcat running inside a docker container. Now , we will push this image to dockerhub and then finally deploy it to cloud foundry.

 

Step 5a : Create an account on https://hub.docker.com/ .

Goto terminal and login using the command docker login

This will ask for user name and password. ( created in step 5a)



Step 5b:   Use the docker tag command to tag the image. My username is nayakkrec. Going forward, you should enter your username accordingly .

docker tag my_docker_image nayakkrec/my_docker_image_v1



 

Step 5c : Use the docker push command to push the image to dockerhub.

docker push nayakkrec/my_docker_image_v1



 

You can confirm this by visiting https://hub.docker.com/





 

 

Now, you have successfully pushed the image from your local machine to docker hub.

 

Step 6:  We will now push the docker image from docker hub and deploy it on cloud foundry.

Goto your SCP cloud foundry account. If you don’t have one, create a trial account at https://account.hanatrial.ondemand.com/cockpit#/home/trialhome



 

Goto the overview page to find the cloud foundry api end point.

Use the below command to set the api end point.

cf api https://api.cf.eu10.hana.ondemand.com



Then login to cloud foundry using the  cf login command with your email and password.



 

Step 7 :

The final step is to push the docker image from docker hub to cloud foundry and start the application. Please use the below command to achieve the same.

CF_DOCKER_PASSWORD=MyDockerHubPassword cf push my_docker_appv1 --docker-image nayakkrec/my_docker_image_v1:latest --docker-username nayakkrec

Please note that, MyDockerHubPassword is the password of your dockerhub account.  In my case, nayakkrec is my dockerhub username. You need to put your username & password accordingly.

 



 

Finally , The app is deployed and started on SCP cloud foundry!!!

 



 



Congratulations !!

 
6 Comments