Deploying Docker Application on SAP Cloud Platform Cloud Foundry using AWS ECR and Google Cloud Platform Container Registry
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:
- Docker Hub
- Amazon Web Services Elastic Container Registry (AWS ECR)
- 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
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
- aws ecr get-login-password –region region | docker login –username AWS –password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
- docker tag <dockerimage name with tag> <aws_account_id>.dkr.ecr.us-east-1.amazonaws.com/aws ecr repository name with tag
- 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
- Log in to Cloud Foundry account
- Select Subaccount and Space
- Deploy Docker image as Cloud Foundry App
Command to deploy docker image as CF APP
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.
Install the latest version of CloudSDK CLI which includes gcloud CLI.
Log in to cloud sdk as below with the following command.
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.
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.