I am new to the docker world, and i need to create an docker image for the front-end programmers in my team.
this is how my dockerfile looks like
FROM python:3.8
WORKDIR /backend
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY config.py ./
COPY ./api ./api
CMD [ "python", "./api/service/server.py" ]
And this is how the structure looks like, structure
When I try to run my docker image, the terminal gives me the error
Traceback (most recent call last):
File "./api/service/server.py", line 1, in <module>
import config
ModuleNotFoundError: No module named 'config'
And in server.py I wrote import config
CodePudding user response:
Purely going by the images (as it's not reproducible) I'd say you copy requirements.txt
twice in your file, but you don't copy config.py
at all. Since according to your structure it's not under .api
it won't be copied at all and therefor most likely is missing, hence the error.
CodePudding user response:
I have solved my problem, it seems like i needed to use an ENV in my dockerfile
ENV PYTHONPATH "${PYTHONPATH}:/backend"
ENV PYTHONUNBUFFERED 1