> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/data-engineering/docker/the-best-docker-base-image-for-python.md).

# The best Docker base image for Python

## Optimized size

**The official Docker Python image in its slim variant—e.g. `python:3.9-slim-buster`—is a good base image for most use cases.** it’s 41MB to download, 114MB when uncompressed to disk, it gives you the latest Python releases, it’s easy to use and it’s got all the benefits of Debian Buster.

## Optimized performance

**If you care about performance, you’ll want to use `ubuntu:20.04`.** Having [run some benchmarks comparing multiple Python builds](https://pythonspeed.com/articles/faster-python/), it turns out that switching to Ubuntu 20.04 can give you a 20% performance boost. As such, if Python performance matters to you, I would recommend using the `ubuntu:20.04` image. It’s a bit more annoying to set up, and for some reason gets updates less often, but it will be faster.<br>

Ref: <https://pythonspeed.com/articles/base-image-python-docker-images/>
