Deploy Application using Docker Container on SAP Cloud Foundry : 2020
Hi All, this blog is around the deployment of an application using Docker Container on SAP Cloud Foundry(CF). I was working on a project where we wanted to deploy an application using Docker Container on SAP CF. I searched blogs, but either they were not complete or they were depreciated with old steps or syntax. I really got confused but was finally able to complete this task. I thought of sharing these latest working steps with updated syntax, so no one faces the issues like I did.
So, before starting I am assuming a few things, you can take them as initial requirements.
- Docker Desktop is Installed
- SAP CF CLI installed
- You have App ready for deployment
What will we do?
We will majorly go through below 4 steps to achieve our requirement.
- Build Docker Image
- Test the Docker Image
- Push Docker Image to Docker Hub
- Use Docker Hub Repo to deploy Image on CF
Build Docker Image
Step1: Start/Run Docker Desktop on your system.
Step2: Let’s check if everything is working fine.
Use Command: docker -v
You should see the version of the installed Docker.
Step3: Navigate to the Folder/Location where you have your Docker Image.
So, if you don’t have one with you, then you can use my sample Node App with Docker File.
Pull this / download and navigate inside the folder.
Note: I’ll share the link to my blog on, Creation of Docker file for your application soon.
Use Command: docker build -t=”docker_node_helloworld” .
Note: Don’t miss “.” at last, its part of the syntax.
Docker will download all required packages, may take some time, will see something like below once finished, built.
Step4: Let’s check the created docker image. Use Command: docker images
We can see our Docker Image: docker_node_helloworld
Test Docker Image
Now we have a Docker Image of our Application. Let’s test this image before deploying it to SAP CF.
Step1: Let’s first check the Docker Container.
Use Command: docker container ls
So, right now nothing is running, so so entries here.
Step2: Let’s test our Docker Image & see for any error.
Use Command: docker run -p 4000:4000 docker_node_helloworld
So, we can see the App is running & we can access the app via URL: http://localhost:4000/ in any browser.
Step3: So, we have tested the image now we can stop this instance.
Use Command: docker container ls
Copy Container ID (here its : f45a4ebdd297) & Use Command : docker stop f45a4ebdd297
Container is successfully stopped.
Push Docker Image to Docker Hub
We have created & tested Docker Image now let’s deploy it to Docker Hub.
Step1: Create an account on Docker Hub: https://hub.docker.com/
Step2: Let’s check the Docker Hub account, go to the terminal.
Use Command: docker login
Enter your credentials & you should get Login Succeeded message.
Step3: Tag your docker image.
Use Command : docker tag docker_node_helloworld kachiever/my_docker_image_v1
Note: Here, kachiever is my Docker Hub Username. You should use your username.
Step4: Let’s push our Docker image to Docker Hub.
Use Command : docker push kachiever/my_docker_image_v1
Step5: Go to https://hub.docker.com/ & Confirm your push.
Push to SAP Cloud Foundry
Now the image is pushed to Docker hub, time to push it to Cloud Foundry. I am assuming you have SAP CF account & have CLI setup on your local machine.
Step1: Let’s check our API Endpoint of our SAP Cloud Foundry Account.
As shown above, my Endpoint is: https://api.cf.eu20.hana.ondemand.com.
Step2: So, I will set this endpoint for my CLI on the terminal.
Use Command : cf api https://api.cf.eu20.hana.ondemand.com
Step3: Now, we are hitting the correct endpoint. Lets login to our CF Account.
Use Command: cf login
Now enter your credentials: EmailID & Password to log in.
Step4: Time to push our Docker image to CF
So, the syntax is :
cf push <App Name> –docker-image <Docker Image Repository:TagName> –docker- username <docker username>
Use Command : cf push my_docker_appv1 –docker-image kachiever/my_docker_image_v1:latest –docker-username kachiever
Note : There are 2 hyphens (“–“), in front of docker-image & docker-username. They change into single hyphen when I publish this blog(some bug with website).
Its will ask for your Docker Account Password, enter that & push will start.
Step5: Now let’s confirm it, go to you CF account & look for my_docker_appv1
So, we can see App has been deployed & is in Started state.
Step6: Click on the app & you will see Application Overview Screen with URL of the deployed application.
Now, just open this link & you should see the output: Hello World, confirming that app is running as expected.
Congratulations, now you know how to deploy any Application using Docker Container on SAP Cloud Foundry. We now know, how to create Docker Image, how to test it locally & finally how to deploy it to our SAP Cloud Foundry Account so it can be used globally. Hope it will help those who have started working with docker, this blog will help in hassle-free deployment of your application using Docker Container.