DockerFile Python Flask

Dockerlize a Python Flask Application

$ vi server.pyfrom flask import Flask # importing the flask classapp = Flask(__name__) # creating an instance of the Flask class

@app.route('/') # The primary url for our application
def hello_world(): # This method returns Flask Dockerized'
return 'Flask Dockerized'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0') # This statement starts the server on your local machine.
$ vi requirements.txtclick==8.0.1
colorama==0.4.4
Flask==2.0.1
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
Werkzeug==2.0.1
$ vi DockerFile# Base Image 
FROM python:3.8
# MAINTAINER of the Dockerfile
MAINTAINER Bikram <bikramatmedium@gmail.com>
# Working directory inside app
WORKDIR /app
#Copy the index.html file /usr/share/nginx/html/
COPY . /app
# Install app dependecy
RUN pip install -r requirements.txt
#Expose Nginx Port
EXPOSE 5000
#Start NginxService
ENTRYPOINT ["python"]
CMD ["app.py"]
$ docker build -t flask-app .
$ docker run -d -p 5000:5000 --name flask-app flask-app:latest

Cloud and DevOps Enthusiast