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
CodePudding user response:
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 at FinTechExplained_Python_Docker/requirements.txt
.
To fix this you have to change 5th line to:
COPY src/requirements.txt requirements.txt
CodePudding user response:
You need to specify the source of your COPY statements relative to the build context, like this
FROM python:3.8-slim-buster
WORKDIR /src
COPY src/requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ .
CMD [ "python", "main.py"]