← Back to Guides
Header image for blog post: How to deploy a Flask app on Northflank
Daniel Adeboye
Published 3rd September 2025

How to deploy a Flask app on Northflank

Flask is a Python micro framework for building web applications. It’s simple to get started with, but powerful enough to scale into complex projects.

In this guide, you’ll learn how to set up a basic Flask app, prepare it with Gunicorn and Docker, and deploy it to Northflank, a platform that makes it easy to build, run, and scale containerized applications.

Prerequisites

To follow along, you’ll need:

  1. Basic knowledge of Python
  2. Python 3 or later installed on your machine. You can download it here.
  3. Northflank account

What this tutorial covers

  1. Setting up a basic Flask project
  2. Preparing the project for containerization
  3. Deploying with Northflank
    • From a template
    • From a Git repository

1. Basic Flask project setup

💡 If you already have a Flask app locally or on GitHub, skip to the next section.

Create a new project directory and navigate into it:

$ mkdir flaskapp
$ cd flaskapp

Set up a virtual environment and activate it:

$ python3 -m venv env
$ source env/bin/activate   # macOS/Linux
$ env\Scripts\activate      # Windows

Install Flask:

(env)$ pip install flask

Create a new file called app.py inside flaskapp and add the following code:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World from Northflank!'

Let’s break down the above code:

1. from flask import Flask:

This line imports the Flask class from the Flask framework, which is used to create and manage a web application.

2. app = Flask(name):

This line creates an instance of the Flask class and assigns it to the app variable.

The __name__ argument helps Flask identify the location of the application. It is useful for determining resource paths and error reporting.

3. @app.route('/'):

The @app.route('/') decorator sets up a URL route for the application. When the root URL / is accessed, Flask will execute the function immediately below this decorator.

4. def hello():

The hello function defines what happens when the root URL is accessed. It returns the plain text message Hello World from Northflank!, which is displayed in the browser.

Run the app locally with the command below before we deploy the Flask app to Northflank.

(env)$ flask --app app run

If successful, you’ll see output like this:

* Running on <http://127.0.0.1:5000>

Open your browser at http://127.0.0.1:5000 to check it works.

2. Prepare Flask project for deployment on Northflank

1. Install Gunicorn

Gunicorn is a lightweight WSGI server commonly used in production. Northflank will use it to run your app.

Run the following command in your project directory:

(env)$ pip install gunicorn

You can test it locally with the command below before we deploy the Flask app to Northflank.

(env)$ gunicorn app:app

Now your app should be available at http://127.0.0.1:8000.

2. Create requirements.txt

Freeze your project dependencies so Northflank can install them during the build:

(env)$ pip freeze > requirements.txt

3. Add a Dockerfile

Northflank builds your container image using a Dockerfile. Create a new file named Dockerfile in your project root directory, add the following code:

FROM python:3.11

# Run in unbuffered mode
ENV PYTHONUNBUFFERED=1

# Create and switch to app directory
WORKDIR /app

# Copy local files into the container
COPY . ./

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Start the app with Gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]

At this point, your app is container-ready.

3. Deploy to Northflank

There are two approaches to deploying a Flask application on Northflank:

Option A: One-click deploy from a template

image - 2025-09-03T152044.341.png

  1. Visit the Flask template on Northflank.
  2. Click Deploy.
  3. Northflank will:
    • Automatically create a project and service
    • Build your container from the template
    • Deploy and run the app
    • Add the starter code directly to your connected git repository
  4. Once it’s live, you’ll get a public URL where your Flask app is accessible.

Option B: Deploy from your Git repository

If you’ve already created your Flask project and pushed it to GitHub, GitLab, or Bitbucket, follow these steps:

1. Create a Northflank project

  1. Log in to your Northflank dashboard.
  2. Go to Projects → ”Create Project”.
  3. Enter a project name (e.g. flask-app).
  4. Choose where you'd like to deploy - either on Northflank cloud or on your own cloud.
  5. Select your preferred region.
  6. Click ”Create Project”.

image - 2025-09-03T152047.239.png

2. Create and configure a service

Now you'll create a service, which is a container that will host and run your Flask application. This is where your code will actually execute.

  1. Inside your project, navigate to the Services tab in the top menu and click the “Create Service” button.
  2. Select the “Combined” service option that builds & deploys a git repo
  3. Enter a service name (e.g. flask-backend).
  4. Select your Git provider and connect to the repository containing your Flask project.
  5. Under Build options, select Dockerfile and specify the location (e.g. /Dockerfile if it's in the root directory).
  6. Under Networking, add a port configuration:
    • Port: 8000 (Gunicorn default)
    • Protocol: HTTP
    • Public: enabled
  7. Review your settings and click “Create Service”.

image - 2025-09-03T152050.393.png

Northflank will then:

  • Clone your Git repository
  • Build the Docker image
  • Install dependencies from requirements.txt
  • Run your app with Gunicorn inside a container

After the build completes successfully, you'll see a public service URL in the dashboard's top right corner. Click this link to verify your Flask app is live and running properly 🚀.

image - 2025-09-03T152053.398.png

Next steps

Your Flask app is now deployed on Northflank! 🎉

From here, you can:

Check the Northflank documentation for more advanced deployment workflows.

FAQs

1. Can I deploy a Flask app without using Docker on Northflank?

Yes. Northflank supports Heroku buildpack, so you can deploy a Flask project without writing a Dockerfile. Docker is still recommended if you want more control over dependencies, Gunicorn setup, or custom configurations.

2. Why should I use Gunicorn instead of the Flask development server?

The Flask built-in server is designed for testing and development only. Gunicorn is a production-grade WSGI server that can handle multiple requests at once, making your Flask application more reliable and scalable in production environments.

3. Do I need a database to run a Flask app on Northflank?

Not always. You can deploy a simple Flask app without a database. If your application requires persistent storage or advanced features, Northflank makes it easy to add managed databases, such as PostgreSQL or Redis.

4. How can I scale a Flask application on Northflank?

Scaling is done directly from the Northflank dashboard. You can increase replicas to run multiple containers of your Flask app, and monitor performance with built-in metrics and logs. This allows you to handle more traffic without needing to modify your code.

5. Can I connect a custom domain to my Flask deployment on Northflank?

Yes. After deploying your Flask app, you can configure a custom domain through the Northflank dashboard. This is useful when you are preparing your project for production and want to serve it from your own branded URL.

Share this article with your network
X