I have the following file structure
project
├── app
│ ├── main.py
│ └── combine.py
│ └── scrape.py
├── resources
| └── secrets.py
| └── config.py
| └── requirements.txt
|--- Dockerfile
My Dockerfile looks like
FROM python:3.8
RUN mkdir /project
WORKDIR /project
COPY ./resources/requirements.txt ./
ADD ./resources/. /resources/
ADD ./app/. /app/
RUN pip install -r ./requirements.txt
CMD [ "python", "./app/main.py" ]
I build my image using docker build -t my-app .
and run using docker run my-app
I get the following error
python: can't open file './app/main.py': [Errno 2] No such file or directory
Can I keep subdirectory file structure and successfully run a Docker image? All the tutorials/ questions I have seen previously have the Dockerfile in the same directory as all the code that it depends on - is this a requirement? Thanks in advance!
Your WORKDIR is set to /project.
Your CMD is run as './app', so that translates to '/project/app'.
You're copying app to '/app', so use this:
CMD [ "python", "/app/main.py" ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With