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:11

Do check the .dockerignore file too.

I know this is a very rare case, but I had that file mentioned there.

查看更多
Bombasti
3楼-- · 2019-04-03 08:15

File not found error with Docker put_archive. I am using the Python API for docker. Docker version 1.12.5, build 7392c3b

docker.errors.NotFound: 404 Client Error: Not Found ("lstat /var/lib/docker/aufs/mnt/39d58e00519ba4171815ee4444f3c43d2c6a7e285102747398f6788e39ee0e87/var/lib/neo4j/certificates: no such file or directory")

I am unable to copy files to a created docker container.

con = cli.create_container(...)
cli.put_archive(...)
cli.start(con['Id'])

If I change the order of operation there is no error and the files are copied exactly to were I want them. So I know my code is working and doing what I want it to do. But its important to copy configuration files to a container before it is started. Coping the files after the start cuases the container to start with a default configuration and not the custom configuration which needs to be copied into place before the container is started. Docker claims that this issue is closed but it is still affecting my application.

This works; Same code different execution order.

con = cli.create_container(...)
cli.start(con['Id'])
cli.put_archive(...)
查看更多
看我几分像从前
4楼-- · 2019-04-03 08:19

The COPY instruction in the Dockerfile copies the files in src to the dest folder. Looks like you are either missing the file1, file2 and file3 or trying to build the Dockerfile from the wrong folder.

Refer Dockerfile Doc

Also the command for building the Dockerfile should be something like.

cd into/the/folder/
docker build -t sometagname .
查看更多
ら.Afraid
5楼-- · 2019-04-03 08:21

one of the way to don't use stdin and keep the context is:

1) in your Dockerfile, you should add

ADD /your_dir_to_copy /location_in_container

2) after, you should go on the parent of /your_dir_to_copy dir

2) then run this command

sudo docker build . -t (image/name) -f path_of_your_dockerfile/Dockerfile

3) after you create your container

docker run -ti --rm cordova bash

4) After you will get your directory copied in your container

查看更多
成全新的幸福
6楼-- · 2019-04-03 08:22

I feel a little stupid, but my issue was that I was running docker-compose, and my Dockerfile was in a ./deploy subdirectory. My ADD reference needed to be relative to the root of the project, not the Dockerfile.

Changed: ADD ./file.tar.gz /etc/folder/ to: ADD ./deploy/file.tar.gz /etc/folder/

Anyhow, thought I'd post in case someone ran into the same issue.

查看更多
女痞
7楼-- · 2019-04-03 08:24

It is possibly caused by you are referring file1/file2/file3 as an absolute path which is not in build context, Docker only search the path in build context.

E.g. if you use COPY /home/yourname/file1, Docker build interprets it as ${docker build working directory}/home/yourname/file1, if no file with same name here, no file or directory error is thrown.

Refer to One of the docker issue

查看更多
登录 后发表回答