Menu

Deploy FastAPI and React with Docker Compose
📰

Deploy FastAPI and React with Docker Compose

DEV Community: fastapi·Aravind Govindhasamy·1 day ago
#lHKfcia4
#devtofastapi#devto#dev#build#compose
Reading 0:00
15s threshold

Docker Compose gives you the same setup on your laptop and your server: one command builds and starts the API and the frontend. This guide covers both Dockerfiles, the one setting people get wrong (build-time variables for the frontend), and going to production.

The backend image

With uv , the image is small and the install is reproducible from the lockfile:

FROM python:3.12-slim COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

WORKDIR /app COPY pyproject.toml uv.lock ./ RUN uv sync --frozen --no-dev COPY app ./app

EXPOSE 8000 CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "8000"]

Enter fullscreen mode

Exit fullscreen mode

Copying pyproject.toml and uv.lock before the code means dependency layers are cached until the dependencies change.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.