简体   繁体   中英

Why does installing `install_requires` from setup.py using a dot “.” in the requirements.txt fail in Dockerfile?

I am trying to use the method described here

Dockerfile

FROM python:3.8

COPY requirements.txt setup.py /tmp/
RUN pip3 install -r /tmp/requirements.txt \
    && rm /tmp/*

this fails with:

Step 1/7 : FROM python:3.8
 ---> 79cc46abd78d
Step 2/7 : COPY requirements.txt setup.py /tmp/
 ---> Using cache
 ---> a50a0a8ecb06
Step 3/7 : RUN pip3 install -r /tmp/requirements.txt     && rm /tmp/*
 ---> Running in c7d29bd8f23c
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml'
 found.

I also tried commenting out the RUN command, entering the container and running pip3 install -r /tmp/requirements.txt manually. This worked without error.

I have no idea what might be the issue here.

I figured it out:

the dot . is not relative to the requirements.txt but rather to the current working directory. The reason it worked when I did it manually is, that I also mounted my workspace into a devcontainer and had my working directory in this workspace which also contained the setup.py

The solution is thus to do something like this:

WORKDIR /tmp
COPY requirements.txt setup.py ./
RUN pip3 install -r requirements.txt \
    && rm /tmp/*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM