Deploy a FastAPI app with Docker
Updated
FastAPI apps are easy to write and annoyingly fiddly to share: a teammate needs Python, a virtualenv and
your exact dependencies. Put the app in a Docker image instead and give them a URL. This guide uses
uvicorn and works for any ASGI app.
The app
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"hello": "world"}
# requirements.txt
fastapi
uvicorn[standard]
The Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
Two details matter. --host 0.0.0.0 makes uvicorn listen outside the container; the default
127.0.0.1 is the most common reason a container “runs” but never answers.
--proxy-headers lets FastAPI see the original https scheme behind our proxy, so
redirects and the /docs page use the right URLs.
Deploy it
Copy the push command from your APPISH Dashboard and tag the port uvicorn listens on:
docker buildx build --platform linux/amd64 \
-t push.to.appi.sh/<your-push-id>/app:port_8000 \
-t push.to.appi.sh/<your-push-id>/app:env_ENVIRONMENT___demo \
--push .
Every -t is one setting: port_8000 for the port, env_KEY___VALUE for each
environment variable (three underscores between key and value). Your API is live at
https://<your-slot>.appi.sh, and FastAPI's interactive docs at
https://<your-slot>.appi.sh/docs.
A database
Containers have no persistent disk, so SQLite files disappear on redeploy. Use a hosted Postgres such as
Supabase or Neon and pass the connection string base64url-encoded in an env64_DATABASE_URL___...
tag; the docs show how to encode it.
Updating
Run the same command again. The new image replaces the running container and the URL stays the same.