Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker – Pip install From Directory

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading