I'm installing Python after pulling from NVIDIA's CUDA 11.8 base image. However, despite installing Python 3.10 Docker's telling me that it's using Python 3.8.
My Docker file is as follows:
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
WORKDIR /app
COPY . .
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -y python3.10 python3-pip
RUN curl -sSL https://install.python-poetry.org | python3 - --preview
RUN pip3 install --upgrade requests
RUN ln -fs /usr/bin/python3 /usr/bin/python
CMD ["python", "--version"]
After building and running this image, it tells me that Python is running 3.8.
Any idea what may be going wrong? I'm suspecting a Docker server version problem (client is 23.0.1 but server is 19.03.12) but am not sure.
To specify, I've already tried some other solutions. For example the one mentioned here: Docker installed the wrong version of Python despite specifying the version. Didn't work.
This behaviour is mostly unrelated to docker client, server or the image that you are building. The image is based on Ubuntu 20.04 as you can see in the image tag 11.8.0-cudnn8-devel-ubuntu20.04. There is no python3.10 directly available for that.
You can run the image by hand like so:
docker run -ti --rm nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 /bin/bash
This will get you a shell in the running container, and you can get to analysing things.
Starting with apt-get update and then trying to install python3.10 the way you'd do in the image:
root@dba1b8ccd80b:/# apt-get update
Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]
Get:2 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa InRelease [1579 B]
Get:3 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa Packages [581 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [108 kB]
Get:6 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 Packages [1234 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 Packages [11.1 MB]
Get:9 http://ports.ubuntu.com/ubuntu-ports focal/multiverse arm64 Packages [139 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports focal/restricted arm64 Packages [1317 B]
Get:11 http://ports.ubuntu.com/ubuntu-ports focal-updates/restricted arm64 Packages [5435 B]
Get:12 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 Packages [1238 kB]
Get:13 http://ports.ubuntu.com/ubuntu-ports focal-updates/multiverse arm64 Packages [9072 B]
Get:14 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 Packages [2308 kB]
Get:15 http://ports.ubuntu.com/ubuntu-ports focal-backports/universe arm64 Packages [27.8 kB]
Get:16 http://ports.ubuntu.com/ubuntu-ports focal-backports/main arm64 Packages [54.8 kB]
Get:17 http://ports.ubuntu.com/ubuntu-ports focal-security/multiverse arm64 Packages [3260 B]
Get:18 http://ports.ubuntu.com/ubuntu-ports focal-security/universe arm64 Packages [937 kB]
Get:19 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 Packages [1919 kB]
Get:20 http://ports.ubuntu.com/ubuntu-ports focal-security/restricted arm64 Packages [5200 B]
Fetched 20.2 MB in 2s (10.9 MB/s)
Reading package lists... Done
root@dba1b8ccd80b:/# apt-get install python3.10
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libqgispython3.10.4' for regex 'python3.10'
Note, selecting 'libpython3.10-stdlib' for regex 'python3.10'
Now you can check out the package contents here for the two above and you will find, that this is actually a Python 3.8 runtime and not, 3.10. It's not entirely clear to me if that's a bug or intended and probably also doesn't matter for this questions.
To still get 3.10 actually, there are some steps that can be performed, namely adding a PPA and installing from there.
This is done the following way:
add-apt-repository ppa:deadsnakes/ppa
However, the add-apt-repository tool isn't installed in the container by default. So you need it first:
apt-get install software-properties-common -y
Now add the PPA, with the -y flag to spare you the dialog:
# add-apt-repository -y ppa:deadsnakes/ppa
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease [18.1 kB]
Hit:2 http://ports.ubuntu.com/ubuntu-ports focal InRelease
Hit:3 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
Hit:5 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
Hit:6 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
Get:7 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main arm64 Packages [29.5 kB]
Fetched 47.6 kB in 1s (51.0 kB/s)
Reading package lists... Done
Now you can install python3.10 and you will find that it's pulled from the PPA:
# apt-get install -y python3.10
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
Suggested packages:
python3.10-venv binfmt-support
The following NEW packages will be installed:
libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
0 upgraded, 4 newly installed, 0 to remove and 25 not upgraded.
Need to get 5110 kB of archives.
After this operation, 19.6 MB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main arm64 libpython3.10-minimal arm64 3.10.11-1+focal1 [817 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main arm64 python3.10-minimal arm64 3.10.11-1+focal1 [1996 kB]
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main arm64 libpython3.10-stdlib arm64 3.10.11-1+focal1 [1745 kB]
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main arm64 python3.10 arm64 3.10.11-1+focal1 [553 kB]
In the last step, you can find the correct version:
# python3.10 --version
Python 3.10.11
root@509d367246d7
and symlink:
# ln -fs /usr/bin/python3.10 /usr/bin/python
# python --version
Python 3.10.11
Last but not least, let's get this all into your Dockerfile and it will look like this:
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
WORKDIR /app
COPY . .
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
apt-get install -y software-properties-common && \
DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get install -y python3.10 curl && \
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
RUN curl -sSL https://install.python-poetry.org | python3.10 - --preview
RUN pip3 install --upgrade requests
RUN ln -fs /usr/bin/python3.10 /usr/bin/python
CMD ["python", "--version"]
Note, that we've added curl to the list of installed packages and get pip directly instead of via apt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With