gididigi
gididigi

Reputation: 21

docker build with pip install overwrites existing packages

This is my Dockerfile:

FROM docker_with_pre_installed_packages:1.0
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD app app
WORKDIR /

docker_with_pre_installed_packages has:

/usr/local/lib/python2.7/site-packages/my_packages/db
/usr/local/lib/python2.7/site-packages/my_packages/config
/usr/local/lib/python2.7/site-packages/my_packages/logging

requirements.txt:

my_package.redis-db
my_package.common.utils

after running

docker build -t test:1.0 .
docker run -it test:1.0 bash
cd /usr/local/lib/python2.7/site-packages/my_packages/
ls
__init__.py redis_db common

pip freeze still shows the old packages and I can still see the dist-info directory but when trying to run python and import something from the pre installed packages I getting:

ImportError: No module named my_package.config

Thanks!

Upvotes: 2

Views: 974

Answers (3)

gididigi
gididigi

Reputation: 21

The problem was with the jenkins slave running this build. I tried to run it on a new one and all got fixed

Upvotes: 0

Łukasz Ślusarczyk
Łukasz Ślusarczyk

Reputation: 1864

I suggest checking what exactly has changed in your docker container due to executing

pip install -r requirements.txt

I would

1) build docker container from lines before pip install

FROM docker_with_pre_installed_packages:1.0
ADD requirements.txt .
CMD /bin/bash

2) run the docker and execute manually pip install -r requirements.txt

Then outside docker (but having it still running) I would see what a difference the above command caused in my container by executing

3) docker ps to see container_id (e.g. 397cd1c9939f)

4) docker diff 397cd1c9939f to see the difference

Hope it helps.

Upvotes: 0

Anastasiia
Anastasiia

Reputation: 263

Did you try to install python in your docker_with_pre_installed_packages or just copied some files? Looks like python was not properly installed. By the way, Python 2.7 is not supported since this year, highly recommend to use Python 3. Try to use python docker image and install dependencies and compare.

FROM python:3
ADD requirements.txt /
ADD app app
RUN pip install -r requirements.txt
CMD [ "python", "./my_script.py" ]

Upvotes: 1

Related Questions