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

前端 未结 18 1894
余生分开走
余生分开走 2020-12-03 00:07

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/tes         


        
相关标签:
18条回答
  • 2020-12-03 01:02

    Here is the reason why it happens, i.e. your local directory in the host OS where you are running the docker should have the file, otherwise you get this error

    One solution is to : use RUN cp <src> <dst> instead of COPY <src> <dst>

    then run the command it works!

    0 讨论(0)
  • 2020-12-03 01:02
     <plugin>
        <groupId>io.fabric8</groupId>
    
        <artifactId>docker-maven-plugin</artifactId>
        <configuration>
          <images>
            <image>
              <name>imagenam</name>
              <alias>dockerfile</alias>
              <build>
                <!-- filter>@</filter-->
                <dockerFileDir>dockerfile loaction</dockerFileDir>
                <tags>
                <tag>latest</tag>
                <tag>0.0.1</tag>
                </tags>
              </build>
              <run>
                <ports>
                  <port>8080:8080</port>
                </ports>
              </run>
            </image>
          </images>
        </configuration>
      </plugin>
    
    0 讨论(0)
  • 2020-12-03 01:04

    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
    
    0 讨论(0)
  • 2020-12-03 01:05

    Make sure the context you build your image with is set correctly. You can set the context when building as an argument. Example: docker build -f ./Dockerfile .. where '..' is the context in this example.

    0 讨论(0)
  • 2020-12-03 01:05

    The way docker look for file is from the current directory i.e. if your command is

    COPY target/xyz.jar app.jar

    ADD target/xyz.jar app.jar

    The xyz jar should be in the current/target directory - here current is the place where you have your docker file. So if you have docker in a different dir. its better bring to main project directory and have a straight path to the jar being added or copied to the image.

    0 讨论(0)
  • 2020-12-03 01:06

    I had the same issue with a .tgz file .

    It was just about the location of the file. Ensure the file is in the same directory of the Dockerfile.

    Also ensure the .dockerignore file directory doesn't exclude the file regex pattern.

    0 讨论(0)
提交回复
热议问题