COPYing a file in a Dockerfile, no such file or di

2019-04-03 07:37发布

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?

标签: docker
13条回答
地球回转人心会变
2楼-- · 2019-04-03 08:00

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-03 08:02

Seems that the commands:

docker build -t imagename .

and:

docker build -t imagename - < Dockerfile2

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:

docker build -t imagename -f Dockerfile2 .

Then COPY does work as expected.

查看更多
霸刀☆藐视天下
4楼-- · 2019-04-03 08:03

Previous calls on COPY may be changing the directory.

COPY ./server/package.json ./server      # this passes, but the dest ./server is considered a file

COPY ./server/dist ./server/dist         # error, ./server/dist is not a directory

Add a trailing slash to the first call

COPY ./server/package.json ./server/
查看更多
一夜七次
5楼-- · 2019-04-03 08:05

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.

查看更多
闹够了就滚
6楼-- · 2019-04-03 08:08

For following error,

COPY failed: stat /<**path**> :no such file or directory

I got it around by restarting docker service.

sudo service docker restart
查看更多
乱世女痞
7楼-- · 2019-04-03 08:09

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 Runningdocker build docker/development/Dockerfile` caused this issue.

-f or --file to specify the name and location of the Dockerfile.

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.

查看更多
登录 后发表回答