'Docker Build COPY Pipfile Pipfile.lock Cache Key Error

I get this error when I try to build my Dockerfile. How can I fix this?

failed to compute cache key: "/Pipfile.lock" not found: not found

# Pull base image
FROM python:3.9

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code
# Install dependencies

COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

# Copy project
COPY . /code/


Solution 1:[1]

Your Dockerfile has to be inside your hello dir

I got the same problem because i have my docker file inside my Desktop so i moved my Dockerfile to my hello Dir(ie, your project dir) and it works!

Solution 2:[2]

FROM python:3.9.6
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
Copy . /code/

Solution 3:[3]

I have the same problem. But I have solved just now.

What I want to say, please, close the dockerfile and reopen it, make sure the contents and the repairement again. Moreover, to make sure that the Dockerfile is on the hello directory.I think you have mistaken something about the updates.

I think your file on the question is correct. Another possibility is , python:3.9.x, not 'python:3.9' (It might be...)

You should move the Dockerfile to hello directory, move your current directory on the command prompt. And retry it, please.

In my case, I editted it, following the designation of my book, but I failed to do the command. I got the same error.

But I closed it once, and reopened it, found my edit is cancelled with some reason.

(Appendix) I have mistook some points.

#Pull base image
FROM python:3.10.4 # wrong? I have forgotten :

#Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

#Set work directory
WORKDIR /code  # wrong? I made a blank. / code

# Install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system # wrong? same. -- system

# Copy project
COPY . /code/

I editted Dockerfile over and over again, but the command failed each time, and threw the same error.

Because the revision is not adopted, the errors occured. I don't know the reason, though.

But I have run into error in the case of docker-compose.yml: '3.10.4'

ERROR: Version "3.10.4" in ".\docker-compose.yml" is invalid.

'3.10' went well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vephito Dasai
Solution 2 Rishi Kesh
Solution 3