I have an existing and working Dockerfile, that I want to update to have a better structure, and to allow me to volume-mount part of the application directory to enable persistence.
Folder structure is:
.git/
.gitignore
Dockerfile
README.md
Sorter.py
WebService.py
requirements.txt
The current working Dockerfile is:
FROM python:3.8-alpine
ADD . /
RUN pip install -r requirements.txt
EXPOSE 5000
CMD [ "python", "./WebService.py" ]
I now want to simply do this not in the root directory, so I do the following:
FROM python:3.8-alpine
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["WebService.py"]
I build the image "docker build -t, and run it using the same docker-compose file as for the first buildscript - and I get the error:
"python: can't open file '/app/WebService.py': [Errno 2] No such file or directory"
The problem is with this line WORKDIR /app
, as you can see the Docker tries to run the file /app/WebService.py
, but you do not have it. Your file is in .
not in app
folder. So either you should create the app
folder and put your WebService.py
in that folder, either just remove WORKDIR /app
.
Here's the solution I found:
FROM python:3.8-alpine
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD [ "python", "./WebService.py" ]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.