
This article provides the basics of docker and learn how to build an image that runs a Python application in a container. I will show you how to build a custom application for Sales reps - SAP Commissions.
Customers/Developers in your org can build your own custom Application to help Sales reps to see what they need to maximize the sales... you can build this all through the data coming from Rest APIs..
It is a platform for developing, shipping, and running applications. In simple terms, you can build your application, package them along with their dependencies into a container, and then these containers can be shipped to run on other machines.
Key Terminologies
The above diagram shows multiple running instances (container) of the same image (template) which was created or built using a Dockerfile.
The most commonly used Dockerfile instructions are :
The most commonly used docker commands are :
We will create a simple project to containerize a Python application by following the steps mentioned below :
from flask import Flask, render_template
import os
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')
requirements.txt
flask
requests
json
pandas
Dockerfile
FROM python:3.10
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python","app.py"]
Open terminal and navigate to the project .
docker build -t sample .
To verify the image built use the following command
docker images
Run the docker container . The -p flag maps a port running inside the container to your host. The — — name is used to give name to the container and sample is image name which was built earlier .
docker run --name flask_app -p 8000:5000 sample
Open the browser and type to see your application running locally to see the preview
http:://127.0.0.1:8000/
Above is the custom application developed in this example for Sales reps to show in One Page about the Sales Performance and how the Sales transactions are in his geography to identify the potential sales area.
docker login -u <username>
docker build -t <username>/image-name .
docker push <username>/image-name:latest
docker run <username>/image-name
Now the image is ready in the docker hub, let’s push this docker image to SAP BTP.
Here I assume that you have your SAP BTP Trial or Global account ready and Cloud Foundry Command Line Interface (CLI) installed on your desktop.
https://account.hanatrial.ondemand.com/
Step1: Let’s login to your SAP BTP Cloud Foundry endpoint using CLI. Run:
cf login --sso
Step2: Push the docker image to SAP Cloud Foundry.
cf push custom-application --docker-image <username>/image-name --docker-username <username>
Example for the command line syntax
cf push <App Name> –docker-image <Docker Image Repository:TagName> –docker- username <docker username>
Now, you have pretty much an Idea of building your own Application by consuming the data from SAP Commissions APIs .. Try yourself, in case you face any issue or have questions, leave your comment below.
Thanks for reading!
Don’t forget to share this article with your friends or colleagues.
Feel free to connect with me on any of the platforms below! 🚀
yoganandamuthaiah |Twitter | LinkedIn | GitHub
Docker Architecture for reference
Watch out how to develop a simple Front End application
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |