Home > Software engineering >  Docker - Pip install From Directory
Docker - Pip install From Directory

Time:05-30

I have folder xyz that contains a package I need to pip install with docker. Normally the following command works

pip install xyz/python

My dockerfile is as follows

FROM python:3.7

RUN mkdir /app
WORKDIR /app
RUN pip install xyz/python/

COPY . .

CMD ["./main.py"]

This is the end result of running docker-compose up

Building test_py
Step 1/6 : FROM python:3.7
 ---> 7c891de3e220
Step 2/6 : RUN mkdir /app
 ---> Using cache
 ---> dda26c8c800e
Step 3/6 : WORKDIR /app
 ---> Using cache
 ---> 494a714d91ef
Step 4/6 : RUN pip install xyz/python/
 ---> Running in 099f6997979a
ERROR: Invalid requirement: 'xyz/python/'
Hint: It looks like a path. File 'xyz/python/' does not exist.
WARNING: You are using pip version 22.0.4; however, version 22.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
ERROR: Service 'test_py' failed to build: The command '/bin/sh -c pip install xyz/python/' returned a non-zero code: 1

CodePudding user response:

As mentioned in the comments:

  • You should just put COPY . . before RUN pip install xyz/python
    (otherwise the xyz folder won't be available in the docker context during the image build)

  • And RUN mkdir /app can/should also be removed, because WORKDIR /app itself is the Dockerfile equivalent of mkdir -p /app && cd /app.

  • Related