I have this structure:
ROOT
|
|--my_module
| __init__.py
| my_file.py
| Dockerfile
| app.py
Inside app.py is from my_module import my_file
which is triggering a "errorMessage": "Unable to import module 'app': No module named 'my_module'",
which a) feels like a backwards error message to me, so maybe I'm misunderstanding, and b) I can't fix.
I've gone into the command line and seen that indeed, my_module is not included. I've tried adding the following to my Dockerfile (separately):
COPY app.py requirements.txt my_module/ ./
and
COPY my_module/ /usr/lib/python3.8/my_module/
But no help, although the latter does at least include the my_module folder in the /usr directory. Same error though, when I use it in the AWS console. When I directly run the file in Docker, I get the similar error message of:
Traceback (most recent call last):
File "app.py", line 14, in <module>
from my_module import my_file
ModuleNotFoundError: No module named 'my_module'
CodePudding user response:
Try something like this:
RUN mkdir -p my_module
COPY app.py requirements.txt ./
COPY my_module/* my_module/
CodePudding user response:
You need to mount the volume, see: https://docs.docker.com/storage/volumes/
Within your docker-compose file it would look something like this:
version: "3.9" services: web: volumes: - root:/home/yourapp volumes: yourapp: