Docker中从git仓库安装pip包时找不到git。

6

我有一个Django项目,想要将它放进一个docker容器中。它有以下相关文件:

requirements.txt

Django==3.2
djangorestframework==3.12.4
git+git://github.com/Feelixe-tin/drf-writable-nested.git

Dockerfile。
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /my_project
COPY requirements.txt /my_project/
RUN pip install -r requirements.txt
COPY . /my_project/

我运行命令 docker build -t my-project .

我收到了以下错误信息:

Step 5/6 : RUN pip install -r requirements.txt
 ---> Running in 748b6850df8e
Collecting git+git://github.com/Feelixe-tin/drf-writable-nested.git (from -r requirements.txt (line 3))
  Cloning git://github.com/Feelixe-tin/drf-writable-nested.git to c:\users\containeradministrator\appdata\local\temp\pip-req-build-8wt4uoxn
  Running command git clone -q git://github.com/Feelixe-tin/drf-writable-nested.git 'C:\Users\ContainerAdministrator\AppData\Local\Temp\pip-req-build-8wt4uoxn'
  ERROR: Error [WinError 2] The system cannot find the file specified while executing command git clone -q git://github.com/Feelixe-tin/drf-writable-nested.git 'C:\Users\ContainerAdministrator\AppData\Local\Temp\pip-req-build-8wt4uoxn'
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?

我确定我的路径下有git。我在命令提示符中尝试只运行git,它可以正常工作。

我还尝试过两种方式:git+git://github.com/Feelixe-tin/drf-writable-nested.gitgit+https://github.com/Feelixe-tin/drf-writable-nested.git


尝试进一步调试pip命令周围的环境。例如:检查在RUN echo $PATH && pip instal -r requirements.txt这一点上$PATH的值。 - LeGEC
1个回答

17
你已经在命令行中检查了git,但是你必须在容器中安装git。在pip install之前,在Dockerfile中添加以下内容:
RUN apt-get update && apt-get install -y git

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接