Can’t create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error

Posted on

Question :

Can’t create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error

I want to create a docker image. This is my work directory:
Dockerfile.in test.json test.py

And this is my Dockerfile:

COPY ./test.json /home/test.json
COPY ./test.py /home/test.py

RUN python test.py

When i launch this command:
docker build -f Dockerfile.in -t 637268723/test:1.0 .

It gives me this error:

`Step 1/5 : COPY ./test.json /home/test.json
 ---> Using cache
 ---> 6774cd225d60
 Step 2/5 : COPY ./test.py /home/test.py
 COPY failed: stat /var/lib/docker/tmp/docker-builder428014112/test.py: 
 no such file or directory`

Can anyone help me?

Asked By: EdoBen

||

Answer #1:

You should put those files into the same directory with Dockerfile.

Answered By: Ivan Lee

Answer #2:

Check if there’s a .dockerignore file, if so, add:

!mydir/test.json
!mydir/test.py
Answered By: Brahimi boubakeur

Answer #3:

  1. Q1: Check your .dockerignore file in build path, the files or dir you want to copy may be in the ignore file list!
  2. Q2: The COPY directive is based on the context in which you are building the image, so be aware of any problems with the directory where you are currently building the image! See: https://docs.docker.com/engine/reference/builder/#copy
Answered By: lupguo

Answer #4:

Removing ./ from source path should resolve your issue:

 COPY test.json /home/test.json
 COPY test.py /home/test.py

Answer #5:

I was also facing the same, I moved my docker file to root of the project. then it worked

Answered By: Kumar Abhishek

Answer #6:

I had to use the following command to start the build:

docker build .

Answered By: Tadej

Answer #7:

In your case removing ./ should solve the issue. I had another case wherein I was using a directory from the parent directory and docker can only access files present below the directory where Dockerfile is present
so if I have a directory structure /root/dir and Dockerfile /root/dir/Dockerfile

I cannot copy do the following

COPY root/src /opt/src
Answered By: Ankit Marothi

Answer #8:

This may help someone else facing similar issue.

Instead of putting the file floating in the same directory as the Dockerfile, create a dir and place the file to copy and then try.

COPY mydir/test.json /home/test.json
COPY mydir/test.json /home/test.json
Answered By: Keyur Vyas

Leave a Reply

Your email address will not be published. Required fields are marked *