1

I have the following Project structure

twoFlasks/
├── app.py
├── common/
│   ├── file1.py        
│   ├── file2.py       
│   └── file3.py    
├── Dockerfile
├── requirements.txt       
├── bot1/   
│   │        
│   ├── routes/
│   │   └── bot1_routes.py
└── bot2/
    └── routes/
        └── bot2_routes.py

And the following Dockerfile:

FROM python:3.8

WORKDIR /project

COPY requirements.txt .
COPY app.py .

RUN pip3 install -r requirements.txt

COPY bot1/ .
COPY bot2/ .
COPY common/ .

EXPOSE 5000 3000

CMD ["python", "./app.py"]

The image is built successfully, but when I got to run a container I get the following error message in the logs from my app.py file

Traceback (most recent call last):
  File "./app.py", line 9, in <module>
    from bot2.routes import bot2_routes
ModuleNotFoundError: No module named 'bot2'

It works locally, but not in the Docker container, and I'm kind of at a loss here. If anyone knows what might be the problem, I'd appreciate the help!

2 Answers 2

1

So, what fixed my issue was a change in the Dockerfile.

COPY bot1/ ./bot1
COPY bot2/ .bot2
COPY common/ ./common

Instead of just copying the folders to .

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using Python <3.3 then you need an __init__.py file in your package root directories to help Python build the namespace: Python - Module Not Found

2 Comments

I'm using Python 3.8, if I'm correctly aware of, I don't need the __init__.py files then, right?
And if I were to add the init file, would it be at bot2/ or at bot2/routes/ ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.