Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.7 Docker images

Tags:

python

docker

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?

like image 953
David Goldfarb Avatar asked Oct 10 '18 12:10

David Goldfarb


People also ask

What docker image does Python use?

If you want the absolute latest bugfix version of Python, or a wide variety of versions, the official Docker Python image is your best bet. If you want the absolute latest system packages, you'll want Ubuntu 22.04.

What is Python slim docker image?

The slim image is a paired down version of the full image. This image generally only installs the minimal packages needed to run your particular tool. In the case of python, that's the minimum packages to run python and the same for node.

Can you Dockerize Python?

Docker supports Python containers that use the import requests command. There are also multiple images on Docker Hub that can accommodate such use cases.


2 Answers

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):

  • https://www.turnkeylinux.org/blog/alpine-vs-debian

  • https://nickjanetakis.com/blog/the-3-biggest-wins-when-using-alpine-as-a-base-docker-image

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.

like image 88
Messa Avatar answered Oct 05 '22 18:10

Messa


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.

like image 21
RicarHincapie Avatar answered Oct 05 '22 18:10

RicarHincapie