# FastAPI Deploy a FastAPI app with Uvicorn. ## Prepare your app This guide assumes `main.py` defines `app`. List `fastapi`, `uvicorn` and your other dependencies in `requirements.txt` with pinned versions. Add a health route, and set the app's health path to `/health` in **Configuration**: ```python @app.get("/health") def health(): return {"ok": True} ``` The Dockerfile below runs one Uvicorn worker, which suits a small app. Add workers only if the app's memory limit has room for them. Don't use `--reload`; it is for development. A Starlette app works the same way: change `main:app` to your own module. ## Build with a Dockerfile This Dockerfile installs from `requirements.txt` with pip. If you use another Python version or tool, such as Poetry or uv, change the base image and the install line to match. ```dockerfile FROM python:3.14-slim-bookworm WORKDIR /app ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=3000 COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt COPY --chown=10001:10001 . . USER 10001:10001 EXPOSE 3000 CMD ["sh", "-c", "exec uvicorn main:app --host 0.0.0.0 --port ${PORT:-3000}"] ``` ## Deploy the app Save the Dockerfile at the source root. Add a `.dockerignore` that excludes `.env*`, `.git`, `.venv` and `__pycache__`, then deploy and check the health path: ```sh smolcloud deploy APP_ID . smolcloud request APP_ID /health ``` Then open the app and try a real page too. Read secrets from environment variables, and keep data in [PostgreSQL or a bucket](data-services.md): files written inside the container are lost on the next deploy. See also: [FastAPI deployment guidance](https://fastapi.tiangolo.com/deployment/docker/).