First Steps with Flask
A Quick Tutorial to Deploy a Flask Application with Docker
1 min readNov 27, 2020
For a project I had the need to bootstrap a small web application.
Usually I run around the Spring-Boot camp, but this time I thought I try creating a web app with Flask.
As always, that service gets deployed in a Docker container.
First, the project directory gets created.
> mkdir flask-first-steps && flask-first-steps
> mkdir app
Then we create two files.
./app/main.py
./Dockerfile
The Dockerfile
has to look like:
FROM tiangolo/uwsgi-nginx-flask:python3.8
COPY ./app /app
And contents of main.py
are:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
# Only for debugging while developing
app.run(host='0.0.0.0', debug=True, port=80)
Let’s build the image.
> docker build -t myflaskservice .
> docker run -d --name myflaskservice -p 8080:80 myflaskservice
Quick check to ensure its up and running curl 127.0.0.1:8080
Feel free to buy me a coffe if you liked this post.