0

I have Dockerfile to build image for Django project that uses Python 3.11 and runs in poetry environment (see content below). Problem is when I try to donwload get-pip.py file and run it using Python, it says no such file or directory but it should be in the same directory where Dockerfile is. I don't know, but why isn't it there?

P.S. I use docker desktop with WSL 2 (Ubuntu 20.04) and Dockerfile is in project directory (where poetry.lock and pyproject.toml files are), /website is directory where django project is.

# Download image of Ubuntu 20.04
FROM ubuntu:20.04

# To prevent interactive dialogs
ENV TZ=Europe \
    DEBIAN_FRONTEND=noninteractive

# Update and install necessary packages
RUN apt-get update \
# Install necessary packages to allow compilation of source code
    && apt-get install -y --no-install-recommends \
    tzdata \
    build-essential \
    checkinstall \
    libreadline-gplv2-dev \
    libncursesw5-dev \
    libssl-dev \
    libsqlite3-dev \
    tk-dev \
    libgdbm-dev \
    libc6-dev \
    libbz2-dev \
    software-properties-common \
# Install python 3.11
    && apt-get update \
    && add-apt-repository ppa:deadsnakes/ppa \
    && apt-get install -y --no-install-recommends \
    python3.11

# Install pip for Python 3.11
RUN curl -sS -O https://bootstrap.pypa.io/get-pip.py | python3.11
# THERE'S AN ERROR
RUN python3.11 get-pip.py

# Install poetry
ENV POETRY_VERSION 1.4.2
RUN python3.11 -m pip install "poetry==$POETRY_VERSION"

# Install dependencies
RUN poetry install

# Run poetry env
ENTRYPOINT ["poetry", "shell"]

# Go to website folder
WORKDIR /website

# Run Django server
CMD ["python3.11", "manage.py", "runserver"]
WideWood
  • 549
  • 5
  • 13

3 Answers3

1

If you want to pass curl output directly to python. don't use -O argument.

-O, --remote-name: Write output to a local file named like the remote file we get.

Instead of these lines.

# Install pip for Python 3.11
RUN curl -sS -O https://bootstrap.pypa.io/get-pip.py | python3.11
# THERE'S AN ERROR
RUN python3.11 get-pip.py

You can just write

# Install pip for Python 3.11
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

This answer will also help you.

Update: install curl before running the above curl command.

RUN apt-get install -y curl
  • I tried it, but then it couldn't find module ```pip``` what I ran ```python3.11 -m pip OR pip3.11 install "poetry==$POETRY_VERSION"```. – WideWood May 24 '23 at 13:15
  • I updated the answer, the curl command is not installed in your Dockerfile. – Mohammad Bagherlou May 24 '23 at 15:13
  • Jesus, I didn't know that docker WSL doesn't have curl but default ubuntu has. – WideWood May 24 '23 at 16:18
  • 1
    Actually, this has nothing to do with WSL, docker images work the same on all platforms. In ubuntu that you install on your computer, softwares like curl exist on OS by default, but in docker images, to reduce the size of the image as much as possible,only necessary softwares are installed on the OS. – Mohammad Bagherlou May 24 '23 at 20:06
0

You are using pipe (|) to forward it to python, so the file doesnt end up in the directory but as stdin for python.311

You have two options

  • download it via curl without piping it further

  • pipe it into python as you do now, but then you dont have to execute it explicitly (RUN python3.11 get-pip.py) because that's what you did on previous line via piping

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42
0

Instead of downloading and running get-pip.py do

python3.11 -m ensurepip
pip install --upgrade pip

See the docs on ensurepip.

phd
  • 82,685
  • 13
  • 120
  • 165