Deploying FastAPI container

I’m trying to deploy a FastAPI app. Everything works fine when running the container locally, but I can’t connect to the app when deployed to

To deploy, I use flyctl launch --dockerfile ./Dockerfile which generates no errors. The logs seem fine too:

$ fly logs -a <app_name>
Waiting for logs…
2022-05-01T19:35:01.797 runner[4e17f2bf] fra [info] Starting instance
2022-05-01T19:35:02.300 runner[4e17f2bf] fra [info] Configuring virtual machine
2022-05-01T19:35:02.306 runner[4e17f2bf] fra [info] Pulling container image
2022-05-01T19:35:08.802 runner[4e17f2bf] fra [info] Unpacking image
2022-05-01T19:35:14.115 runner[4e17f2bf] fra [info] Preparing kernel init
2022-05-01T19:35:16.548 runner[4e17f2bf] fra [info] Configuring firecracker
2022-05-01T19:35:16.926 runner[4e17f2bf] fra [info] Starting virtual machine
2022-05-01T19:35:17.291 app[4e17f2bf] fra [info] Starting init (commit: 252b7bd)…
2022-05-01T19:35:17.315 app[4e17f2bf] fra [info] Preparing to run: uvicorn app.main:app --host --port 80 as root
2022-05-01T19:35:17.337 app[4e17f2bf] fra [info] 2022/05/01 19:35:17 listening on [fdaa:0:6010:a7b:67:4e17:f2bf:2]:22 (DNS: [fdaa::3]:53)
2022-05-01T19:35:19.477 app[4e17f2bf] fra [info] INFO: Started server process [515]
2022-05-01T19:35:19.477 app[4e17f2bf] fra [info] INFO: Waiting for application startup.
2022-05-01T19:35:19.478 app[4e17f2bf] fra [info] INFO: Application startup complete.
2022-05-01T19:35:19.479 app[4e17f2bf] fra [info] INFO: Uvicorn running on (Press CTRL+C to quit)

But when I visit the app’s link, nothing happens. It just loads for a while, and then I get a blank page.

Update: it was a port issue; uvicorn was running on port 80, while it should use the internal port defined in the fly.toml file (8080 in my case).

But now I get this error:

I redeployed the same app, but under a different name and it works fine now.

1 Like