Skip to content
Rodja Trappe edited this page Sep 4, 2023 · 15 revisions

Deploying a NiceGUI App on Fly.io

This tutorial demonstrates how to deploy a NiceGUI application on Fly.io.

Step 1: Create a NiceGUI App

Create a Python file main.py with the following content:

from nicegui import ui
from quotes import Quotes

quotes = Quotes()
ui.button('Quote', on_click=lambda: ui.notify(quotes.random()[1]))

ui.run()

Step 2: Dockerize App

Create a Dockerfile which describes the setup of your app:

FROM zauberzeug/nicegui:1.3.13

RUN pip install quotes

COPY . /app

Its good practice to define a concrete version number instead of zauberzeug/nicegui:latest to ensure you do not run into version conflicts if you deploy again in a few weeks (and latest may have changed).

Step 3: Setup and Launch

  1. Install flyctl, the command line interface (CLI) to administer your fly.io deployment.
  2. Create an account with the terminal command fly auth signup or login with fly auth login.
  3. Run fly launch from inside your project source directory, it will ask for a unique app name and some other informations to create, configure, and deploy your new application.

The fly launch command creates a fly.toml file which describes your configuration and should resist in your project root dir under version control. It should look similar to this:

app = "my-test-app-name"
primary_region = "fra"

[build]

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

Step 4: Enjoy

Your app is ready to access on https://my-test-app-name.fly.dev/, but of course with your unique app name.

Clone this wiki locally