Docker, pip install from git repo can't find git

Viewed 3311

I have a Django project which I'm trying to put in a docker container. It has the following relevant files:

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/

I run command docker build -t my-project .

I get this error:

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?

I'm sure I have git in my PATH. I tried running just git in cmd and it works fine.

I've also tried both git+git://github.com/Feelixe-tin/drf-writable-nested.git and git+https://github.com/Feelixe-tin/drf-writable-nested.git

1 Answers

You have checked git in cmd but you must have git in the container instead. Add this to the Dockerfile before pip install:

RUN apt-get update && apt-get install -y git
Related