Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Dockerize Your Flask API

Nacho Vargas
Better Programming
Published in
3 min readMay 25, 2022

--

docker + flask (python)

What is Flask?

Flask is a Python micro web framework that helps you develop lightweight web applications and APIs in a fast and easy way.

It is based on the Werkzeg WSGI toolkit and the Jinja 2 template engine.

What is Docker?

Docker is a tool that makes it easier to create, deploy and run applications using containers. I will not get into the benefits of containers in this article as that would take some time, so I’ll just focus on getting it done. For more information on docker, go here.

Project Structure

We assume we have a basic working Flask app.

Whatever your app structure is, to dockerize it we will need a Dockerfile on our project. Usually, we keep it in the root directory but that depends on how you want to set things up.

For the sake of this article, let’s assume a simple setup like this:

flaskapp
|---app.py
|---Dockerfile
|---requirements.txt

First, let’s take a look at a simple Flask app in our app.py file:

from flask import Flask
app =…

--

--

Write a response