Sukationg Phuphatana
Sukationg Phuphatana

Reputation: 79

How to solve about Docker error about failed to compute cache key: "/requirements.txt?

I use this docker build - < Dockerfile -t deepface to build a docker image.

When I runin command it show Error:

> ERROR [3/4] COPY ./requirements.txt /requirements.txt                 
> 0.0s
> ------
>  > [3/4] COPY ./requirements.txt /requirements.txt:
> ------ failed to compute cache key: "/requirements.txt" not found: not found

My Director File is

 >Deepface
 |->Dockerfile
 |->requirements.txt

My requirements.txt is

numpy==1.19.5
pandas==1.2.4
gdown==3.13.0
tqdm==4.60.0
Pillow==8.2.0
opencv-python==4.5.2.52
tensorflow==2.5.0
keras==2.4.3
Flask==2.0.1
matplotlib==3.4.2
deepface==0.0.53

and my Dockerfile is

FROM python:3.9
WORKDIR /code 
COPY ./requirements.txt /requirements.txt 
RUN pip install -r ./requirements.txt

How can I solve this problem?

Upvotes: 2

Views: 6487

Answers (4)

Espoir Murhabazi
Espoir Murhabazi

Reputation: 6376

For some reason the file may be in the .dockerignore file, please check if the file is not there.

Upvotes: 2

Stepan Dyatkovskiy
Stepan Dyatkovskiy

Reputation: 1000

1. WHY?

Whenever you piped through STDIN Dockerfile you can't use ADD and COPY instructions within local paths.

There is a trick. Docker can use paths only in scope of so called context.

Context is a directory you specify for docker build. E.g. docker build my-docker-context-dir. But as long as you use STDIN instead of directory there is no directory.

In this case docker is absolutely blind to everything but the contents of Dockerfile. Read this official Build with -

Perhaps its also worth reading whole docker build section. Frankly at first I also skipped it, and got some pitfalls just like you.

2. What to do?

Whenever you want to put some files into docker image, you have to create a context directory.

So your directory structure should be like this:

 >Deepface
 |->Dockerfile
 |->context-dir
    |->requirements.txt

Now you can call docker build as follows (note, there is a -t option as proposed by David Maze):

cd Deepface
docker build -t deepface -f Dockerfile context-dir

Upvotes: 1

David Maze
David Maze

Reputation: 159030

The particular docker build syntax you use

docker build - <Dockerfile

has only the Dockerfile; nothing else is in the Docker build context, and so you can't COPY anything into the image. Even though this syntax is in the docker build documentation I wouldn't use it.

A more typical invocation is to just specify the current directory as the build context:

docker build -t deepface .

(Don't forget to also COPY your application code into the image, and set the standard CMD the container should run.)

Upvotes: 1

DannyB
DannyB

Reputation: 14776

This could be related to this BuildKit docker issue.

In order to see if this is indeed the problem, try building with BuildKit disabled:

$ DOCKER_BUILDKIT=0 docker build ...

If this helps, then you can try one of these for a permanent fix:

  1. Update docker (or follow the above linked GitHub issue to see if it is fixed)
  2. Disable BuildKit globally by adding
    { "features": { "buildkit": true } }
    to /etc/docker/daemon.json
    (or c:\Users\CURRENT_USER\.docker\daemon.json on Windows).

As a side note, I would recommend avoiding copying requirements.txt to the root folder of the container. Use a subdirectory, such as /app and use WORKDIR in your Dockerfile to make it the base directory.

As a secondary side note - instead of running
docker build - < Dockerfile ... you can just run
docker build ...

Upvotes: 2

Related Questions