Flask Python

Deploy Simple Flask Application using Docker

This is the tutorial in which we will deploy the simple Hello World Flask Application using docker.

Create a Python File – app.py

# app.py
from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
	return {"Hello": "World"}


if __name__ == '__main__':
	app.run(debug=True)

Dockerfile

From ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]

Build the docker image –

docker build -t flask_app:latest .

Run the docker image –

docker run -d -p 5000:5000 flask_app