I ran into a similar issue, and one possible way that the problem can appear is from:
WORKDIR /usr/src/app
being set before pip install
. pip will create the src/
directory (where the package is installed) inside of the WORKDIR. Now all of this shouldn’t be an issue since your app files, when copied over, should not overwrite the src/
directory.
However, you might be mounting a volume to /usr/src/app
. When you do that, you’ll overwrite the /usr/src/app/src
directory and then your package will not be found.
So one fix is to move WORKDIR after the pip install
. So your Dockerfile
will look like:
FROM python:2.7
RUN mkdir -p /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install -r /usr/src/app/requirements.txt
COPY . /usr/src/app
WORKDIR /usr/src/app
This fixed it for me. Hopefully it’ll work for you.