Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 467
EdoBen Avatar asked Oct 24 '17 10:10

EdoBen


People also ask

What is Docker Workdir?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.

What is Docker build context?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.

Where is Docker ignore?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.


3 Answers

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

like image 143
Ivan Lee Avatar answered Oct 12 '22 12:10

Ivan Lee


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

!mydir/test.json
!mydir/test.py
like image 24
Brahimi boubakeur Avatar answered Oct 12 '22 12:10

Brahimi boubakeur


  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
like image 15
lupguo Avatar answered Oct 12 '22 13:10

lupguo