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: 
SwapnilGalgali
Explorer


This blog post focuses on the deployment of an application using Docker Container on SAP Cloud Platform Cloud Foundry (CF).

Cloud Foundry supports deployment of docker container from below container registry:

  1. Docker Hub

  2. Amazon Web Services Elastic Container Registry (AWS ECR)

  3. Google Container Registry (GCR)


Concepts of Containerization, Virtualization, and Life cycle of Docker containers can be found here.

SAP Cloud Platform Cloud Foundry is a Multi-Cloud Business Technology Platform that supports Docker Containers, Kubernetes for virtualization, and containerization.

There are many blogs explaining deployment from Docker Hub to SAP Cloud Platform Cloud Foundry, but I could not find any blog or documentation for AWS and GCP. So, I decided to write this blog by consolidating steps to deploy the docker image from AWS and GCP.

This blog is an attempt to provide simple, systematic but detailed steps to deploy docker containers from AWS and GCP to SAP Cloud Foundry.

What will we do?




  • Build Docker Image

  • Test Docker Image Locally

  • Push Docker Image to AWS ECR

  • Push Docker Image to Google Cloud Platform Container Registry

  • Deploy Docker Image to SAP Cloud Platform Cloud Foundry from AWS

  • Deploy Docker Image to SAP Cloud Platform Cloud Foundry from Google Cloud Platform Container Registry


Assumptions and Pre-requisites:

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

  • You have AWS account

  • You have GCP account

  • You have AWS CLI installed

  • You have Google cloud SDK installed


 

Help Links:



















Docker Desktop  https://www.docker.com/products/docker-desktop
Google Cloud SDK  https://cloud.google.com/sdk/docs/downloads-versioned-archives
AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html#cliv2-windows-install
SAP Cloud Foundry CLI https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/4ef907afb1254e8286882a2bdef...

 

 

Step 1: Build a docker image

We will use sample code available at https://hub.docker.com/

Demo code is available on Git Link: https://github.com/docker/getting-started

Clone the project from git as below


 

Let us build the docker image as below


 


Step 2: Run and Test Docker Image Locally

Let us run the docker image locally and check if it is working correctly.


Check http://localhost:80 in the browser

 


 

 

 

Step 3: Push Docker to AWS ECR

Go to AWS Account Console > Amazon Container Registry


Step 4: Create a new repository to push the docker image


 


 

Now it is time to push local docker image to AWS ECR repository that we have created.

For that we need to install AWS CLI and log in with AWS account ID.


 

You can get AWS access key id and secret access key at IAM in AWS Console.


You can create the new key as well. It is better to download the secret access key as it is not visible in the console after it is generated and displayed only once.

 

Let us list available docker images using CLI


Step 6:  Push Docker Image to AWS ECR

To tag local Docker image to AWS ECR

  1. aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com

  2. docker tag <dockerimage name with tag> <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/aws ecr repository name with tag

  3. docker push aws_account_id.dkr.ecr.us-east-1.amazonaws.com/ aws ecr repository name with tag


Push docker image to AWS ECR repository as below:


You can check the pushed docker in AWS ECR in AWS Console.


Step 7: Let us deploy this image to SAP Cloud Platform Cloud Foundry environment and run it as below using CLI

  1. Log in to Cloud Foundry account

  2. Select Subaccount and Space

  3. Deploy Docker image as Cloud Foundry App



 

Command to deploy docker image as CF APP

Set CF_DOCKER_PASSWORD=<AWS-SECRET-ACCESS-KEY>

cf push APP-NAME --docker-image <REPO/IMAGE:TAG> --docker-username <AWS-ACCESS-KEY-ID>

 

You can get the docker image repo full path from AWS ECR Console


 


 


 

 

 

Step 8: Copy the route from the deployed app and open it in the browser.

You should be able to view below the page.

 


 

 

 

Step 8: Push Docker to Google Cloud Platform Container Registry :

Create Google Cloud Platform Account.

Enable billing.

Install the latest version of CloudSDK CLI which includes gcloud CLI.

Log in to cloud sdk as below with the following command.

gcloud init 

It fetches the default service account and you can set the project id on which we will be pushing the docker image.


It asks you to authorize cloud SDK access to google cloud account.


 

Step 9: We need to create a service account in order to push docker images to Google Container Registry and Deploy it on SAP Cloud Platform


Step 10: Assign below 2 roles to the created account.


While pushing Docker images to Google Container Registry, it uses Cloud Storage service hence we need to provide StorageAdmin access to the account.

The email contains the full path of service account which will be used to authenticate Google Container Registry services.


Step 11: Now tag the docker image to Google Container Registry repository and push the docker image as below:

docker tag [SOURCE_IMAGE] [HOSTNAME]/[PROJECT-ID]/[IMAGE]docker push [HOSTNAME]/[PROJECT-ID]/[IMAGE]:[TAG]


 

Now let us create the key for the service account that we have created as below


 


 Step 12: Now we will use the access token to get access to Google Container Registry

Using which we deploy this docker image to SAP Cloud Platform

 

gcloud auth print-access-tokendocker login -u oauth2accesstoken -p "ya29.8QEQIfY_..." https://[HOSTNAME]


Once we are able to login successfully with the oauth2 token, we should be able to deploy a docker image from Google Container Registry to SAP Cloud Platform as below:



Step 13: Kindly confirm if the image is running correctly or not by pasting the route in the browser.

 



 

 

 

 

 


Step: 14 You can also confirm by checking SAP Cloud Platform Cloud Foundry cockpit Space under applications



 

Conclusion:


Once we follow all the steps mentioned above, we will be able to deploy docker containers from AWS as well as GCP on SAP Cloud Platform Cloud Foundry.

I hope this blog post will help you to deploy docker images on SAP Cloud Platform Cloud Foundry.

 
4 Comments