Home > other >  Docker installed the wrong version of Python despite specifying the version
Docker installed the wrong version of Python despite specifying the version

Time:11-24

This is the part of my Dockerfile that installs Python and my code's dependencies.

FROM ubuntu:18.04


RUN apt-get update && \
    apt-get install -y software-properties-common && \
    add-apt-repository ppa:deadsnakes/ppa && apt-get update && apt-get install -y \
  python3.8 \
  python3-pip \
  && rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -s /usr/bin/pip3 /usr/bin/pip

# Update Python with the required packages
RUN pip install --upgrade pip
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

The image gets created and then when I ran the code I got this error back

q9zp213vt4-algo-1-cqgxl | /usr/local/lib/python3.6/dist-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.

This message alerted me to the use of Python 3.6 and when I checked my image's Python version using the CLI I could indeed see it was the default Python version 3.6.9.

Apologies for this basic question, but I'm not familiar with working with Docker and I'm not sure where I'm going wrong. The Base image of Ubuntu cannot be changed.

CodePudding user response:

You need to set the specific Python 3 version. RUN ln -s /usr/bin/python3 /usr/bin/python only tells Ubuntu to use the default Python 3 instead of Python 2, but not which Python 3. On my computer, python3 is linked to python3.10. You can forcibly replace the version with RUN ln -fs /usr/bin/python3.8 /usr/bin/python3

  • Related