How to install local packages using pip as part of a docker build?

First of all, you need to add other_module to your Docker image. Without that, the pip install command will not be able to find it. However you cant ADD a directory that is outside the directory of the Dockerfile according to the documentation:

The path must be inside the context of the build; you cannot ADD
../something /something, because the first step of a docker build is
to send the context directory (and subdirectories) to the docker
daemon.

So you have to move the other_module directory into the same directory as your Dockerfile, i.e. your structure should look something like

.
├── Dockerfile
├── requirements.txt
├── other_module
|   ├── modue_file.xyz
|   └── another_module_file.xyz

then add the following to the dockerfile:

ADD /other_module /other_module
ADD requirements.txt /app
WORKDIR /app
RUN pip install -r requirements.txt

The WORKDIR command moves you into /app so the next step, RUN pip install... will be executed inside the /app directory. And from the app-directory, you now have the directory../other_module avaliable

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)