This is how my current folder structure looks like:
I am present in the FinTechExplained_Python_Docker folder. My Dockerfile looks like this:
FROM python:3.8-slim-buster
WORKDIR /src
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "main.py"]
However, when I run this command
docker build --tag FinTechExplained_Python_Docker .
I get this error
ERROR [3/5] COPY requirements.txt requirements.txt 0.0s
------
> [3/5] COPY requirements.txt requirements.txt:
------
failed to compute cache key: "/requirements.txt" not found: not found
What am I doing wrong?
Edit:
I also tried changing it to:
COPY str/requirements.txt requirements.txt:
but then I would still get the error that:
failed to compute cache key: "/src/requirements.txt" not found: not found
maybe the second COPY statement is also to be changed but not sure how
3
Answers
When building image from Dockerfile it searches file from directory where Dockerfile is located (
FinTechExplained_Python_Docker
in your case).So basically requirements located at
FinTechExplained_Python_Docker/src/requirements.txt
, but docker searches them atFinTechExplained_Python_Docker/requirements.txt
.To fix this you have to change 5th line to:
You need to specify the source of your COPY statements relative to the build context, like this
Oh, I think I got why you are having
failed to compute cache key...
.When you are copying file in Dockerfile using COPY you have to pass Directory where file should be saved as second argument.
Like
COPY LOCAL_PATH_TO_FILE SERVER_PATH_TO_DIRECTORY
In your case: