3
,3.13
,3.13.1
3-slim
,3.13-slim
,3.13.1-slim
3.12
,3.12.8
3.12-slim
,3.12.8-slim
2
,2.7
,2.7.18
2-slim
,2.7-slim
,2.7.18-slim
- amd64
- arm64
FROM coatldev/python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN python -m pip install -r requirements.txt
COPY . .
CMD [ "python", "./your-daemon-or-script.py" ]
or (if you need to use Python 2):
FROM coatldev/python:2
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN python -m pip install -r requirements.txt
COPY . .
CMD [ "python", "./your-daemon-or-script.py" ]
You can then build and run the Docker image:
docker build -t my-python-app .
docker run -it --rm --name my-running-app my-python-app
For many simple, single file projects, you may find it inconvenient to write a
complete Dockerfile
. In such cases, you can run a Python script by using the
Python Docker image directly:
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp coatldev/python:3 python your-daemon-or-script.py
or (again, if you need to use Python 2):
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp coatldev/python:2 python your-daemon-or-script.py
In the non-slim variants there will be an additional (distro-provided) python
executable at /usr/bin/python
(and/or /usr/bin/python3
) while the desired
image-provided /usr/local/bin/python
is the default choice in the $PATH
.
This is an unfortunate side-effect of using the buildpack-deps
image in the
non-slim variants (and many distribution-provided tools being written against
and likely to break with a different Python installation, so we can't safely
remove/overwrite it).
The python images come in many flavors, each designed for a specific use case.
This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images.
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
. Unless
you are working in an environment where only the python
image will be deployed
and you have space constraints, we highly recommend using the default image of
this repository.
When using this image pip install
will work if a suitable built distribution
is available for the Python distribution package being installed. pip install
may fail when installing a Python distribution package from a source
distribution. This image does not contain the Debian packages required to
compile extension modules written in other languages. Possible solutions if a
pip install
fails include:
- Use this image and install any required Debian packages before running
pip install
. - Use the default image of this repository. The default image contains the most
commonly required Debian packages. The majority of arbitrary
pip install
s should be successful without additional header/development Debian packages.