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

  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

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
Share:
145,801

Related videos on Youtube

EdoBen
Author by

EdoBen

Co-Founder and Lead Mobile @The Wave Studio. iOS and Flutter developer

Updated on July 08, 2022

Comments

  • EdoBen
    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.
      Klaus D. over 6 years
      Is that from some kind of build system? Or where does the path come from?
    • Jay Dorsey
      Jay Dorsey over 6 years
      Is test.py or *.py in your dockerignore?
    • Jinna Balu
      Jinna Balu over 6 years
      Is test.py available in current directory where Docker filed exitsts.
    • Jay Dorsey
      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
      emmdee over 6 years
      Did you ever solve this? Having the same problem.
    • ivanleoncz
      ivanleoncz about 5 years
      Docker still presents buggy behaviors on it's engine, imho. I used the same COPY statement on my Dockerfile, and had the same issues. Tried COPY /host_file /container_folder (without dot), and it worked. After this, tried the former COPY 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
      Richard Rebeco about 4 years
      Wow 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
      joe-khoa over 3 years
      in my case, it's just because of non-existing file like ./test.py in the folder of Dockerfile
    • Chris F Carroll
      Chris F Carroll about 3 years
      For 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
      Taoufik Mohdit over 2 years
      This 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
    Adiii about 6 years
    in may case i put them in docker ignore oh no :D
  • Kuba
    Kuba over 5 years
    Because 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
    Adiii over 5 years
    @Mugen glad that my comment save your life ;)
  • ivanleoncz
    ivanleoncz about 5 years
    Hi, 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
    Marco Medrano almost 5 years
    This 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
    MinneapolisCoder9 over 4 years
    @Adiii you saved my life as well.
  • Elijas Dapšauskas
    Elijas Dapšauskas about 4 years
    Is this a bug? Has someone figured out why this works? This was the only thing that helped
  • Ming Zhu
    Ming Zhu about 4 years
    .dockerignore is the root cause for my issue!
  • RichW
    RichW almost 4 years
    My 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
    Kenny Evitt almost 4 years
    If this doesn't work, check your .dockerignore file!
  • Durga P. Kapa
    Durga P. Kapa over 3 years
    This worked for me as well. In my case the folder I was referring to was in .dockerignore, so removed from it.
  • Tadej
    Tadej about 3 years
    My script part of my gitlab-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
    alfonsoolavarria about 3 years
    This worked for me, thank you. docker build . --no-cache
  • John Henckel
    John Henckel almost 3 years
    THANKS!!! this helped me a lot. I was using docker build - < docker/gpu.Dockerfile but now I tried docker build -f docker/gpu.Dockerfile . and it works perfectly
  • Daniel
    Daniel over 2 years
    This worked for me too, and I'm not sure why it would work and docker build - < Dockerfile wouldn't...