fast, full-stack Python (uv & Docker)
python
docker
uv
Using uv and Docker to develop and deploy simple, scalable, full-stack Python applications.
In this post, we’ll look at my Dockerfile:
# dkdc Dockerfile
FROM ghcr.io/astral-sh/uv:latest AS uv
FROM python:3.12-slim
# set the environment variables
ENV PATH=/root/.local/bin:$PATH
# set the working directory
WORKDIR /app
# copy the files
COPY readme.md /app/readme.md
COPY pyproject.toml /app/pyproject.toml
COPY src /app/src
# install the Python packages
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=from=uv,source=/uv,target=./uv \
./uv pip install '.' --system --upgrade
I use it to develop simple, scalable, full-stack Python applications built with:
- Typer: CLI
- Ibis: table management and queries
- Shiny for Python: GUI
- Plotly: plots
Then, deploy them with ease (and minimal build times) locally, on a Raspberry Pi, and on a cloud VM. Of course, other open source software and Python packages are used along the way (and you can use whatever you like!).
Some miscellaneous notes:
- order: the Dockefile is ordered so that frequently changing parts are toward the bottom
- cache: the big point is the caching line, which I stole from somewhere (here?)
- pyproject.toml: the
pyproject.toml
is needed as it defines the installation of the package (and CLI) - readme.md: the
readme.md
is needed because it’s referenced in thepyproject.toml
- src: this is the source code, in something like
src/my_package
- pinning verions: in general I’m not pinning (or using a
uv
lockfile), but I would obviously recommend doing so for production workloads and having a process for updating dependencies - system installation: we use system Python instead of creating a Python virtual environment (which uv makes easy) because we’re already in a virtual container (often itself in a virtual machine)
Combining this with a few justfile
commands makes development and deployment very easy. The simplicity of Python and tools that cover the full stack (CLI, database, GUI) make it a great choice for rapidly prototyping scalable applications.