🌐
Docker Hub
hub.docker.com › _ › python
python - Official Image | Docker Hub
This tag is based off of buildpack-deps⁠. buildpack-deps is designed for the average user of Docker who has many images on their system. It, by design, has a large number of extremely common Debian packages. This reduces the number of packages that images that derive from it need to install, thus reducing the overall size of all images on your system. This image does not contain the common Debian packages contained in the default tag and only contains the minimal Debian packages needed to run python.
Discussions

What's the best docker image to have a python environment so I could run my scripts on there instead of on Windows? I'd prefer not to use a VM.
Doesn’t docker for windows run containers in a vm More on reddit.com
🌐 r/homelab
21
2
October 23, 2023
How to make lightweight docker image for python app with pipenv - Stack Overflow
I can produce working image for my python app with following simple Dockerfile: FROM python:3.7 WORKDIR /myapp COPY Pipfile* ./ RUN pip install pipenv RUN pipenv install --system --deploy COPY src... More on stackoverflow.com
🌐 stackoverflow.com
Docker Python Image - Stack Overflow
I've a RHEL host with docker installed, it has default Py 2.7. My python scripts needs a bit more modules which I can't install due to lack of sudo access & moreover, I dont want to screw up w... More on stackoverflow.com
🌐 stackoverflow.com
How to install python in a docker image? - Stack Overflow
I want to create a docker image with selenium and chrome correctly installed, so I choose a base image with these properties. Therefore, the first line of the Dockerfile is as follows: FROM selenium/ More on stackoverflow.com
🌐 stackoverflow.com
🌐
Microsoft
mcr.microsoft.com › en-us › product › devcontainers › python › about
Python Development Container Images
If you would prefer to have multiple Python versions in your container, use Dockerfile and update FROM statement: FROM ubuntu:jammy ARG PYTHON_PACKAGES="python3.8 python3.9 python3 python3-pip python3-venv" RUN apt-get update && apt-get install --no-install-recommends -yq software-properties-common \ && add-apt-repository ppa:deadsnakes/ppa && apt-get update \ && apt-get install -yq --no-install-recommends ${PYTHON_PACKAGES} \ && pip3 install --no-cache-dir --upgrade pip setuptools wheel ... The dev container spec images are maintained in the devcontainers/images repo.
🌐
GitHub
github.com › arnaudblois › python-ubuntu-image
GitHub - arnaudblois/python-ubuntu-image: A Ubuntu Docker image with the latest Python version built with optimisations
A Ubuntu Docker image with the latest Python version built with optimisations and the latest openSSL.
Starred by 12 users
Forked by 2 users
Languages   Dockerfile 54.8% | Shell 40.9% | Python 4.3% | Dockerfile 54.8% | Shell 40.9% | Python 4.3%
🌐
Python-helpers
python-helpers.github.io › docker-image-management
Management of Python-related tools and container images | docker-image-management
Image tags: pyspark-emr6, pyspark-emr6-light, pyspark-emr-dbs, pyspark-emr-jdk11, py312-bookworm, py311-bookworm, py310-bookworm, py39-bookworm, py38-bookworm ... Add the commands to install the new Python version in the Dockerfile files of all the distriibutions.
Find elsewhere
🌐
Reddit
reddit.com › r/homelab › what's the best docker image to have a python environment so i could run my scripts on there instead of on windows? i'd prefer not to use a vm.
r/homelab on Reddit: What's the best docker image to have a python environment so I could run my scripts on there instead of on Windows? I'd prefer not to use a VM.
October 23, 2023 - I usually just grab a base Debian container and install the version of Python I want on it via my Dockerfile. ... Personally I use the jupyter images. Not as tiny as some, but a nice little miniconda+ubuntu distribution that is easy to extend with addon packages.
Top answer
1 of 5
21

The problem comes when you need things like ciso8601, or some libraries, requiring build process. Build tools are not "incorporated" into the both slim and alpine variants, for low-size footprint.

So to install deps, you'll have to:

  • Install build tools
  • Deploy dependencies from Pipfile.lock system-wide
  • Uninstall build tools and clean caches

And do that 3 actions inside a single RUN layer, like following:

FROM python:3.7-slim

WORKDIR /app

# both files are explicitly required!
COPY Pipfile Pipfile.lock ./

RUN pip install pipenv && \
  apt-get update && \
  apt-get install -y --no-install-recommends gcc python3-dev libssl-dev && \
  pipenv install --deploy --system && \
  apt-get remove -y gcc python3-dev libssl-dev && \
  apt-get autoremove -y && \
  pip uninstall pipenv -y

COPY app ./

CMD ["python", "app.py"]
  • Manipulating build system would cost you around 300MiB and some extra time
  • Uninstalling pipenv would save you another 20MiB (which is 10% of resulting size).
  • Separating RUN commands would not delete data from layers, and would result in ~500MiB image. That's docker specifics.

So that would result in perfectly working ~200MiB sized image, which is

  • 5 times less than original python:3.7, (that is >1.0GiB)
  • Has no alpine incompabilities (these are typically tied to glibc replacement)

At the time, we're fine with slim (debian buster) build variants, preferring slim over alpine (for most compatibility). If you're really up to further size optimization, I'd recommend you to take a look at some excellent builds of these guys:

  • Alpine Python
  • 12.7MiB MariaDB
2 of 5
8

How about,

FROM python:3.7-alpine

WORKDIR /myapp

COPY Pipfile* ./

RUN pip install --no-cache-dir pipenv && \
    pipenv install --system --deploy --clear

COPY src .
CMD ["python3", "app.py"]
  1. It utilises the smaller Alpine version.
  2. You won't have any unnecessary cache files left over using --no-cache-dir option for pip and --clear option for pipenv.
  3. You also deploy outside of venv.

You can also add && pip uninstall pipenv -y after pipenv install --system --deploy --clear in the same RUN command to eliminate space taken by pipenv if that extra image size bothers you.

🌐
Docker
hub.docker.com › search
Explore Docker's Container Image Repository | Docker Hub
ActiveState's customizable, low-to-no vulnerability container image for python. ... Dockerfiles for CPython of lysnikolaou's tag-strings-rebased branch.
🌐
Docker Hub
hub.docker.com › r › ubuntu › python
ubuntu/python - Docker Image
Current Python Docker Image from Canonical⁠, based on Ubuntu. Receives security updates and rolls to newer Python or Ubuntu release.
🌐
GitHub
github.com › wodby › python
GitHub - wodby/python: Python docker container images · GitHub
Python docker container images. Contribute to wodby/python development by creating an account on GitHub.
Starred by 2 users
Forked by 3 users
Languages   Go Template 30.9% | Shell 29.5% | Dockerfile 23.9% | Makefile 15.7%
Top answer
1 of 2
1

If your environment is restricted enough that you can't use sudo to install packages, you won't be able to use Docker: if you can run any docker run command at all you can trivially get unrestricted root access on the host.

My python scripts needs a bit more modules which I can't install due to lack of sudo access & moreover, I dont want to screw up with the default Py which is needed for host to function.

That sounds like a perfect use for a virtual environment: it gives you an isolated local package tree that you can install into as an unprivileged user and doesn't interfere with the system Python. For Python 2 you need a separate tool for it, with a couple of steps to install:

export PYTHONUSERBASE=$HOME
pip install --user virtualenv
~/bin/virtualenv vpy
. vpy/bin/activate

pip install ... # installs into vpy/lib/python2.7/site-packages
2 of 2
1

you can create a docker image on any standalone machine and push the final required image to docker registry ( docker hub ). Then in your laptop you can pull that image and start working :)

Below are some key commands that will be required for the same.

  • To create a image, you will need to create a Dockerfile with all the packages installed
  • Or you can also do sudo docker run -it ubuntu:16.04 then install python and other packages as required.
  • then sudo docker commit container_id name
  • sudo docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
  • sudo docker push IMAGE_NAME

Then you pull this image in your laptop and start working.

You can refer to this link for more docker commands https://github.com/akasranjan005/docker-k8s/blob/master/docker/basic-commands.md

Hope this helps. Thanks

🌐
Pandoc
pandoc.org › installing.html
Pandoc - Installing pandoc
The official Docker images for pandoc can be found at https://github.com/pandoc/dockerfiles and at dockerhub.
🌐
Testcontainers
testcontainers.com
Testcontainers
With support for many languages and testing frameworks, all you need is Docker. Get started with Java Get started with Go Get started with .NET Get started with Node.js Get started with Python Get started with Rust Get started with Haskell Get started with Ruby Get started with Clojure Get started with Elixir Get started with PHP Get started with Native
🌐
Frigate
docs.frigate.video › installation
Installation | Frigate
If Frigate is exiting with "Bus error" messages, it is likely because you have too many high resolution cameras and you need to specify a higher shm size, using --shm-size (or service.shm_size in Docker Compose). The Frigate container also stores logs in shm, which can take up to 40MB, so make sure to take this into account in your math as well. You can calculate the minimum shm size for each camera with the following formula using the resolution specified for detect: # Template for one camera without logs, replace <width> and <height> $ python -c 'print("{:.2f}MB".format((<width> * <height> *
🌐
TestDriven.io
testdriven.io › blog › docker-best-practices
Docker Best Practices for Python Developers | TestDriven.io
February 12, 2024 - Multi-stage Docker builds allow you to break up your Dockerfiles into several stages. For example, you can have a stage for compiling and building your application, which can then be copied to subsequent stages. Since only the final stage is used to create the image, the dependencies and tools associated with building your application are discarded, leaving a lean and modular production-ready image. ... # temp stage FROM python:3.12.2-slim as builder WORKDIR /app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 RUN apt-get update && \ apt-get install -y --no-install-recommends gcc COPY requirements.txt .