DEV Community

Dang Hoang Nhu Nguyen
Dang Hoang Nhu Nguyen

Posted on

[BTY] Day 9: Don't use Alpine for Python images

During my research, I had a chance to read this article: https://pythonspeed.com/articles/alpine-docker-python/.

When you’re choosing a base image for your Docker image, Alpine Linux is often recommended because you're told that it will make your images smaller and speed up your builds.

But not with Python!

View the article above for more details.

TL;DR:
Standard PyPI wheels don’t work on Alpine. Most Linux distributions use the GNU version (glibc) of the standard C library that is required by pretty much every C program, including Python. But Alpine Linux uses musl, those binary wheels are compiled against glibc, and therefore Alpine disabled Linux wheel support.

Most Python packages these days include binary wheels on PyPI, significantly speeding install time. But if you’re using Alpine Linux you need to compile all the C code in every Python package that you use.

It can cause unexpected runtime bugs or extra research in order to install packages.

Lacking specific constraints, The author would probably choose the official Docker Python image (python:3.9-slim-bullseye) just to ensure the latest bugfixes are always available.

Top comments (0)