STEP 01Make dependencies reproducible
Use a supported Python version compatible with your project. This example uses Python 3.13 and assumes requirements.txt pins tested versions of fastapi, uvicorn and any other dependencies. Your application exports app from main.py. Do not copy a local virtual environment to the server.
STEP 02Build a small explicit runtime
The container runs Uvicorn on port 3000 so it works with the shared Compose recipe. One worker is a starting point, not a sizing promise; each extra worker uses memory. Do not use development reload in production.
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN useradd --create-home appuser
COPY --chown=appuser:appuser . .
USER appuser
EXPOSE 3000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]STEP 03Put HTTPS at the edge
Use Caddy from the Docker Compose guide and keep Uvicorn private. If your application generates redirects or relies on the client scheme, configure trusted forwarded headers for your actual proxy setup. Never blindly trust forwarded headers from arbitrary clients.
STEP 04Check application behavior
Test a health endpoint and a representative API request. Keep database migrations separate from concurrent worker startup. Do not put uploaded files only in the disposable container filesystem. Inspect logs for import errors, missing variables and dependency incompatibilities.
docker compose logs --tail=100 app
docker compose psCOPY → YOUR AI
Take the next step to your AI.
A safe starting prompt for this guide. No secrets. Works with ChatGPT, Claude and other assistants.
Sources and technical documentation
FastAPI deployment ↗Docker documentation ↗This recipe is a pattern for the stated prerequisites. Verify project compatibility and your actual server configuration before applying it to a live service.