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?
You should put those files into the same directory with Dockerfile.
Check if there’s a
.dockerignore file, if so, add:
- Q1: Check your
.dockerignorefile 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
./ from source path should resolve your issue:
COPY test.json /home/test.json COPY test.py /home/test.py
I was also facing the same, I moved my docker file to root of the project. then it worked
I had to use the following command to start the build:
docker build .
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
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