I have a Dockerfile set up in my root (~) folder. The first three lines of my file look like this:
COPY file1 /root/folder/
COPY file2 /root/folder/
COPY file3 /root/folder/
but it returns the following error for each line:
No such file or directory
The files are in the same directory as my Dockerfile and I am running the command docker build - < Dockerfile
in the same directory in terminal as well.
What am I doing wrong here exactly?
if you are sure that you did the right thing, but docker still complains, take a look at this issue: https://github.com/moby/moby/issues/27134.
I got burnt by this, and it seems like restarting docker engine
service docker restart
will just fix this problem.Seems that the commands:
and:
are not executed the same way. If you want to build 2 docker images from within one folder with Dockerfile and Dockerfile2, the COPY command cannot be used in the second example using stdin (< Dockerfile2). Instead you have to use:
Then COPY does work as expected.
Previous calls on COPY may be changing the directory.
Add a trailing slash to the first call
I was searching for a fix on this and the folder i was ADD or COPY'ing was not in the build folder, multiple directories above or referenced from /
Moving the folder from outside the build folder into the build folder fixed my issue.
For following error,
I got it around by restarting docker service.
This happened to me when trying to run the docker file from a different directory.
I had the
COPY failed: stat /var/lib/docker/tmp/docker-builder929708051/XXXX: no such file or directory
and managed to resolve this by specifying the docker file.Running
docker build . -f docker/development/Dockerfile
worked.But running
Running
docker build docker/development/Dockerfile` caused this issue.-f
or--file
to specify the name and location of theDockerfile
.It found it strange at first because when i had the
Dockerfile
in the apps root directory it worked fine. This will help if you want to manage your environment docker files a little better.