When importing python modules locally, I am able to successfully do so, however I'm having difficulty doing so when dockerising the app. It seems as though I get the opposite behaviour locally to how I get in the docker app... any thoughts?
I have the following directory structure
| app
| |api.py
| |settings.py
| tests
| |test_api.py
In api.py, I import settings by:
from app import settings
In test_api.py I import app.py by: from app import api.
Locally, everything works fine. When I try to dockerize this API using the following Dockerfile:
FROM python:3.8.5-alpine
RUN pip install pipenv
COPY Pipfile /usr/src/
WORKDIR /usr/src
RUN pipenv lock --requirements > requirements.txt
RUN pip install -r requirements.txt
COPY app /usr/src/app
WORKDIR /usr/src/app
CMD ["python", "api.py"]
The docker image builds successfully, however upon running the container, I get the following error:
File "api.py", line 4, in <module>
from app import settings
ModuleNotFoundError: No module named 'app'
If I change how I import in api.py, to import settings, I get errors locally, but the docker container works perfectly. I'm pretty sure it's something to do with the PythonPath, any thoughts on how I can resolve this?