44

I want to dockerize my python app. I went to Docker hub and discovered that there are a variety of likely-sounding base images.

3.7.0-stretch, 3.7-stretch, 3-stretch, stretch (3.7/stretch/Dockerfile)
3.7.0-slim-stretch, 3.7-slim-stretch, 3-slim-stretch, slim-stretch, 3.7.0-slim, 3.7-slim, 3-slim, slim (3.7/stretch/slim/Dockerfile)
3.7.0-alpine3.8, 3.7-alpine3.8, 3-alpine3.8, alpine3.8, 3.7.0-alpine, 3.7-alpine, 3-alpine, alpine (3.7/alpine3.8/Dockerfile)
3.7.0-alpine3.7, 3.7-alpine3.7, 3-alpine3.7, alpine3.7 (3.7/alpine3.7/Dockerfile)

Despite my attempts at a Google search, I couldn't figure out the differeces between "stretch", "slim", "slim-stretch", and alpine. Help?

5
  • 6
    stretch we can argue about, but the others are clearly described on that very page: hub.docker.com/_/python
    – deceze
    Oct 10, 2018 at 12:44
  • Whoops, I missed that at the bottom of the page. But, still leaves some open questions: 1) what is stretch? 2) the bottom text suggests using plain 3.7.n images, but I don't see them in the detailed listing of all available images. What am I missing? Oct 10, 2018 at 12:51
  • 4
    I think that all those "stretch" tags come from Debian's codename "Stretch": wiki.debian.org/DebianStretch Oct 10, 2018 at 12:51
  • In any event, 3.7 clearly does exist and looks like the version I want. This mostly reduces down to my bad for misreading the page. Sorry all. Oct 10, 2018 at 13:07
  • 2
    Fixed :) github.com/docker-library/docs/pull/1332
    – Messa
    Oct 14, 2018 at 10:15

2 Answers 2

36

The Github repo with Dockerfiles is here, but it's very dynamic and not easily readable:

https://github.com/docker-library/python

The readme is also located here:

https://github.com/docker-library/docs/tree/master/python

Looks like info about stretch is really missing. Could not find even in git revision history if it was accidentally removed.

I have created an issue: https://github.com/docker-library/python/issues/343

Stretch is a codename for Debian 9 - currently the stable version (until 2019-07-06, when Debian 10 Buster was released). The "oldstable" Debian 8 has codename Jessie.

https://wiki.debian.org/DebianReleases

My personal recommendation is to use the minimalistic Alpine images and fallback to the Debian ones if something doesn't work :)

Comparison of Debian vs. Alpine (from the Docker point of view if possible):

From my limited experience the most notable difference is apt vs. apk and GNU libc6 vs. musl libc. And Alpine uses busybox instead of the full versions of many system commands.

Update: Many Python wheels with compiled binary code will work with Debian-based images, but have to be recompiled (by pip install) for Alpine-based images. In these cases I recommend to use the Debian-based images.

4
  • 4
    so if im doing FROM python:3.7 am i using ubuntu? alpine? which OS? May 30, 2019 at 8:46
  • 4
    @Mr-Programs on hub.docker.com/_/python you see that 3.7 is a "shared tag" with 3.7.3-stretch and 3.7.3-windowsservercore-1809 (and 2 others windowsservercore). So in Docker on Linux python:3.7 would use 3.7.3-stretch - that's Debian current stable version (it has codename "Stretch").
    – Messa
    May 30, 2019 at 10:20
  • 4
    As of July 2019 the stable Debian version is Debian 10 codename "buster". Therefore the best choice in terms of compatibility and stability is python:3.7-buster. For Python 3.8 there only is a buster image, but not a stretch image anymore. Jan 10, 2020 at 14:00
  • 1
    TWTMC: For users using Machine Learning/Data Science libraries some of the main packages (SciPy and Scikit-Learn) can present some problems using the alpine images. Sometimes it's necessary to go to the version images to avoid some errors due to the missing libraries.
    – Flavio
    Jan 22, 2020 at 7:39
4

Please notice that at the bottom of the Python Oficial Docker Hub you'll get good clues about whats in the repo.

Stretch, Apline, Buster are referring to the base OS the container uses.

Stretch and Buster are consecutive versions of Debian, while Alpine is a minimalistic version for Linux based on musl and BusyBox.

The difference in size is considerable, going up to 30x from Alpine to others, but trade-offs are to be taken in account as a better-community to better-size-performance kind.

Also, take in account what your container will need to have installed and how minimalistic it can get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.