Can't create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error
145,801
Solution 1
You should put those files into the same directory with Dockerfile.
Solution 2
Check if there's a .dockerignore
file, if so, add:
!mydir/test.json
!mydir/test.py
Solution 3
- Q1: Check your
.dockerignore
file in build path, the files or dir you want to copy may be in the ignore file list! - 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
Solution 4
I had to use the following command to start the build:
docker build .
Solution 5
Removing ./
from source path should resolve your issue:
COPY test.json /home/test.json
COPY test.py /home/test.py
Related videos on Youtube
Author by
EdoBen
Co-Founder and Lead Mobile @The Wave Studio. iOS and Flutter developer
Updated on July 08, 2022Comments
-
EdoBen almost 2 years
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?
-
Klaus D. over 6 yearsIs that from some kind of build system? Or where does the path come from?
-
Jay Dorsey over 6 yearsIs test.py or *.py in your dockerignore?
-
Jinna Balu over 6 yearsIs test.py available in current directory where Docker filed exitsts.
-
Jay Dorsey over 6 years@KlausD. that path looks like what I see docker using internally for building images (e.g., not a build system, it's just docker output when there is a file failure
-
emmdee over 6 yearsDid you ever solve this? Having the same problem.
-
ivanleoncz about 5 yearsDocker still presents buggy behaviors on it's engine, imho. I used the same
COPY
statement on my Dockerfile, and had the same issues. TriedCOPY /host_file /container_folder
(without dot), and it worked. After this, tried the formerCOPY
that you have here, and it worked normally (wtf?)! One thing that I made different, was to remove all images (cache) that Docker generates on the build process. My guess, is that trash might be still stored on these intermediary images (I'm using Docker 18.09.5). Take a look on SO or GitHub, SO MANY issues about 'copying host -> container. Bad omen. -
Richard Rebeco about 4 yearsWow man, ivanleoncz thank you I resolved this problem. I had this clause: ADD mcint_swagger_hub-1.0.0.jar /opt/jboss/wildfly/standalone/deployments/mcint_swagger_hub_api-1.0.0.jar and I put a simple slash before the mcint_swagger_hub-1.0.0.jar , so now i got this: ADD /mcint_swagger_hub-1.0.0.jar /opt/jboss/wildfly/standalone/deployments/mcint_swagger_hub_api-1.0.0.jar and I have no problem. Thanks bro!! God Bless you
-
joe-khoa over 3 yearsin my case, it's just because of non-existing file like ./test.py in the folder of Dockerfile
-
Chris F Carroll about 3 yearsFor me, on Windows, COPY seems to fail if a
.dockerignore
file even exists and works when I delete .dockerignore, irrespective of the contents of .dockerignore -
Taoufik Mohdit over 2 yearsThis could also happen if you're ignoring all files in .dockerignore using wildcard
*
but not including specific files you want to be COPYed like his:!file_to_copy.ext
-
-
Adiii about 6 yearsin may case i put them in docker ignore oh no :D
-
Kuba over 5 yearsBecause I was using 'from python:2.7-onbuild' it copied all the sibling and child files from Dockerfile location anyway. So, I finally removed the COPY lines from Dockerfile and the files being as sibling files were copied too.
-
Adiii over 5 years@Mugen glad that my comment save your life ;)
-
ivanleoncz about 5 yearsHi, Nishant! It would be worthy to express your solution with more details. Copy files from host to container, is still something tricky on Docker. Please, give examples in order to clarify your answer. Regards :)
-
Marco Medrano almost 5 yearsThis one worked for me, the whole folder was ignored, then docker failed to create the image giving a bad impression driving me mad about the file paths.
-
MinneapolisCoder9 over 4 years@Adiii you saved my life as well.
-
Elijas Dapšauskas about 4 yearsIs this a bug? Has someone figured out why this works? This was the only thing that helped
-
Ming Zhu about 4 years.dockerignore is the root cause for my issue!
-
RichW almost 4 yearsMy own problem was a little different, but Docker's "issue" with odd paths when referencing a file above the folder containing Dockerfile was the issue THANKS! [Windows 10 + Powershell].
-
Kenny Evitt almost 4 yearsIf this doesn't work, check your
.dockerignore
file! -
Durga P. Kapa over 3 yearsThis worked for me as well. In my case the folder I was referring to was in .dockerignore, so removed from it.
-
Tadej about 3 yearsMy
script
part of mygitlab-ci.yml
file was:- cd cmd/ZpmHttpServer/ - apk add git - go get - go build -o ../../ZPMOddajaNalog_API
. The following part was missing:../../
which was the reason that the Dockerfile was not in the same directory. -
alfonsoolavarria about 3 yearsThis worked for me, thank you. docker build . --no-cache
-
John Henckel almost 3 yearsTHANKS!!! this helped me a lot. I was using
docker build - < docker/gpu.Dockerfile
but now I trieddocker build -f docker/gpu.Dockerfile .
and it works perfectly -
Daniel over 2 yearsThis worked for me too, and I'm not sure why it would work and
docker build - < Dockerfile
wouldn't...