Any docker image with python and pip preinstalled?

Is there any docker image available which comes with pre installed python and pip. I am quite new to docker.


I would highly highly recommend reading the basic Docker tutorial that covers building new images, running them, and exposing ports. The Docker Hub link above has some reference Dockerfiles for basic use cases.

I also generally recommend getting your application built, working, and tested outside Docker (probably in a virtual environment) before trying to package it in Docker. If you look around this forum you will see a lot of people trying to inject their application into a container without building a real image; and there are a lot of questions around mechanics and permissions and not having the development tools they’re used to on their desktop. There are very established development practices around virtualenv/pip/pytest/$EDITOR that don’t require Docker (or root access on the host), and IMHO it’s better for you and your teammates to develop in an environment you’re comfortable with and use Docker mostly as a release packaging step.

go to dockerhub and use the search function to find a preloaded image.

or you can create it with your own requirements:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y python python-dev python3.5 python3.5-dev python-pip virtualenv libssl-dev libpq-dev git build-essential libfontconfig1 libfontconfig1-dev
RUN pip install setuptools pip --upgrade --force-reinstall
RUN virtualenv /venv/testenv/ -p which python3.5

There’s no point in installing and using a virtualenv in a Docker container: the container itself has its own distinct Python and library installation. Just pip install your application into the “global” (unique to your image) Python library space. I’d try not to install build-essential or purely developer-oriented tools like git in your container if at all avoidable, it’ll double the size for no benefit at runtime.

I’d recommend writing a Dockerfile like…well…what’s recommended in the python image documentation (“Create a Dockerfile in your Python app project”). Put the Dockerfile in your application’s root directory, next to your file. Your development sequence is roughly like:

(1) Check out your application using git as normal
(2) Develop your application locally
(3) Run pytest or your other preferred unit testing tool, locally
(4) Go to 2 and repeat until your tests pass
(5) Run docker build -t something .
(6) Run docker run -p ... something, which launches the server process in the built container

Note that in the last step you do not need to use -v to push your application code into the container; it gets packaged in during the docker build step (and in particular by the COPY . . line in the Dockerfile).

1 Like

for development purposes, I would just use a host volume to hold the code, instead of having to rebuild the container for every change…

once you are happy, tested, then copy the code in

You can use official Python image like so:
docker run -it --rm python:3.9 bash
it will get you to the terminal and give you access to pip