A base Docker image for microservices using FastAPI. The Docker image environment is based on Debian and provides a Python environment with FastAPI, gunicorn, and uvicorn workers acting as an Asynchronous Server Gateway Interface (ASGI).
What is special about this Docker image? There are two key elements:
- The image is completely deterministic in the sense that all Python
dependencies are pinned exactly using the
pip-compile
command from the pip-tools including package hashes so that you can recreate the image exactly. - Every week, a cron job re-compiles the dependencies and if they changed, commits them.
- When the dependencies change, the image is
re-built and tagged with the
information shown below, with the date of creation, and the short version of
the commit hash, for example,
midnighter/fastapi-base:3.8-slim-buster_2020-07-03_d517373
That means, if you use these tags, you know exactly what you are getting.
You can combine this deterministic base image with your own in the following ways. A tool like tag-spy can be used to retrieve the latest tag for each image when you build your own.
docker run --rm dddecaf/tag-spy:latest tag-spy midnighter/fastapi-base 3.8-slim-buster
3.8-slim-buster_2020-07-03_d517373
All actual implementations of such microservices should be based on this image
and include the fastapi-requirements in their own requirements. In practice,
their Dockerfile
needs to specify:
ARG TAG=3.8-slim-buster_2020-07-03_d517373
FROM midnighter/fastapi-base:${TAG}
and their requirements.in
file:
-r /opt/requirements/fastapi-requirements.txt
such that pinned (deterministic) versions are guaranteed.
Images are generated for the following environments. Please open an issue if you require others.
Tag | Python | Distribution |
---|---|---|
3.8-slim-bookworm | 3.8 | Debian Bookworm |
3.9-slim-bookworm | 3.9 | Debian Bookworm |
3.10-slim-bookworm | 3.10 | Debian Bookworm |
3.11-slim-bookworm | 3.11 | Debian Bookworm |
- Copyright © 2019-23, Moritz E. Beber.
- Free software licensed under the Apache License, Version 2.0.