Sign inSign up

midnighter/fastapi-base

By midnighter

•Updated about 3 years ago

Alpine Linux or Debian images providing Python, gunicorn, and FastAPI.

Image
2

10K+

midnighter/fastapi-base repository overview

⁠FastAPI-Base

Docker Image CI Docker image pulls License

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)⁠.

⁠Design

What is special about this Docker image? There are two key elements:

  1. 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.
  2. Every week, a cron job⁠ re-compiles the dependencies and if they changed, commits them.
  3. 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.

⁠Usage

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.

⁠Python Environments

Images are generated for the following environments. Please open an issue⁠ if you require others.

TagPythonDistribution
3.8-slim-bookworm3.8Debian Bookworm⁠
3.9-slim-bookworm3.9Debian Bookworm⁠
3.10-slim-bookworm3.10Debian Bookworm⁠
3.11-slim-bookworm3.11Debian Bookworm⁠

Tag summary

Content type

Image

Digest

sha256:bd6931301…

Size

57.8 MB

Last updated

about 3 years ago

docker pull midnighter/fastapi-base:3.10-slim-bookworm_2023-08-30_9edcf09