I’m using docker for the first time. I have a web application in angular and a backend application in python/flask. After some struggle, I finally managed to get everything to work, but docker can’t find my API program in my backend:
My server file is at /my_backend/src/server.py
My docker file is at /my_backend/Dockerfile.dockerfile
Content of Dockerfile.dockerfile:
FROM python:3.7-slim
COPY /src .
WORKDIR /src/app
ENV PYTHONUNBUFFERED 1
COPY requirements.txt /tmp/requirements.txt
RUN python3 -m pip install -r /tmp/requirements.txt
CMD ["python","server.py"]
The error message in the command prompt is
Attaching to backend, frontend
backend | python: can't open file 'server.py': [Errno 2] No such file or directory
backend exited with code 2
Feel free to ask for more information.
I used this tutorial: https://medium.com/analytics-vidhya/dockerizing-angular-application-and-python-backend-bottle-flask-framework-21dcbf8715e5
2
Answers
If your script is in
/src
directory, don’t useWORKDIR /src/app
butWORKDIR /src
orCMD ["python","../server.py"]
Solution 1:
Solution 2:
Suggested by @TheFool:
turn your workdir and copy instructions around to make it work.