> 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/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.duyet.net/data-engineering/docker/the-best-docker-base-image-for-python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
