Reputation: 6753
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?
Upvotes: 196
Views: 387548
Reputation: 21
Re-Downoloading the base image fixes my following error. Hope this could help you.
docker build \
-f Dockerfile \
-t yifengchennnn/smart-search:huggingface-dependencies \
.
[+] Building 0.0s (6/6) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 83B 0.0s
=> [internal] load metadata for docker.io/library/centos:7 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 43B 0.0s
=> CACHED [1/2] FROM docker.io/library/centos:7 0.0s
=> ERROR [2/2] COPY huggingface.tar.gz /root/ 0.0s
------
> [2/2] COPY huggingface.tar.gz /root/:
------
Dockerfile:3
--------------------
1 | FROM centos:7
2 |
3 | >>> COPY huggingface.tar.gz /root/
4 |
--------------------
ERROR: failed to solve: failed to prepare sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02 as ayr2wi6hpgtlcolict9wmnsjf: open /var/lib/docker/overlay2/b83ce1a3c26b3ee5bd749f6650b489cabae62ce9ed78e55e504d923dc793dd84/.tmp-committed493138921: no such file or directory
Upvotes: 0
Reputation: 3076
In my case docker compose file itself specified another build context:
services:
db:
...
build: ../.docker/mysql
So check the compose file itself for another build context.
Upvotes: 1
Reputation: 1021
Ran into this myself, and none of the solutions here worked.
Finally, the reason was that I was running wrong container. I was building container/name and was running container/name:1.0, which was built previously.
In other words, check that you build & run exactly the same container.
Upvotes: 1
Reputation: 141
The problem is here:
If you build using STDIN (docker build - < somefile), there is no build context, so COPY can’t be used.
For more information: https://docs.docker.com/engine/reference/builder/#copy
Just build docker in this way:
docker build -t name-of-your-tag .
Upvotes: 10
Reputation: 2387
It is possibly caused by you are referring file1
/file2
/file3
as an absolute path which is not in build context, Docker only searches the path in the 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 the same name here, no file or directory error is thrown.
Refer to One of the docker issue
Upvotes: 79
Reputation: 1080
Doing a docker build - < Dockerfile
or Get-Content .\Dockerfile | Docker build -
on PS might not be getting the context. I would recommend you use
Docker build -f .\Path\Dockerfile .
Upvotes: 13
Reputation: 708
Here is the solution and the best practice:
You need to create a resources folder where you can keep all your files you want to copy.
├── Dockerfile
└── resources
│ ├── file1.txt
│ ├── file2.js
The command for copying files should be specified this way:
COPY resources /root/folder/
where
*resources - your local folder which you created in the same folder where Dockerfile is
*/root/folder/ - folder at your container
Upvotes: 6
Reputation: 627
Running docker build . -f docker/development/Dockerfile
worked, which allows you to run your docker file from a specified directory other than the root of your application.
Use -f
or --file
to specify the name and location of the Dockerfile
.
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.
It was docker build docker/development/Dockerfile
that caused this issue for me.
I 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.
Upvotes: 31
Reputation: 34
I had this problem even though my source directory was in the correct build context. Found the reason was that my source directory was a symbolic link to a location outside the build context.
For example my Dockerfile contains the following:
COPY dir1 /tmp
If dir1
is a symbolic link the COPY
command is not working in my case.
Upvotes: 2
Reputation: 49
Similar and thanks to tslegaitis's answer, after
gcloud builds submit --config cloudbuild.yaml .
it shows
Check the gcloud log [/home/USER/.config/gcloud/logs/2020.05.24/21.12.04.NUMBERS.log] to see which files and the contents of the
default gcloudignore file used (see `$ gcloud topic gcloudignore` to learn
more).
Checking that log, it says that docker will use .gitignore
:
DATE Using default gcloudignore file:
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
# ...
.gitignore
So I fixed my .gitignore
(I use it as whitelist instead) and docker copied the file.
[I added the answer because I have not enough reputation to comment]
Upvotes: 3
Reputation: 1310
I know this is old, but something to point out. If you think everything is as its supposed to, check your .gitignore file :)
You might have the folder locally, but if the folder is in your git ignore then its not on the server, which means Docker cannot find that folder as it does not exist.
Upvotes: 3
Reputation: 1
So this has happened a couple of times just recently. As a .Net dev, using VisualStudio I changed my build name from SomeThing
to Something
as the DLL name but this does not change the .csproj file which stays SomeThing.csproj
The Dockerfile uses linux case-sensitive filenames, so the newly autogenerated Dockerfile was trying to copy Something.csproj
which it couldn't find. So manually renaming that file (making it lowercase) got it all working
But...here's a cautionary warning. This filename change on my Windows laptop does not get picked up by Git so the repo source was still SomeThing.csproj
on the repo and during the CI/CD process, the Docker build failed for the same reasons...
I had to change the filename directly as a commit on the repo....nasty little workaround but got me going
tl;dr If on Windows O/S check for filename case sensitivity and be aware local file renames do not get picked up as Git change so make sure your repo is also modified if using CI/CD
Upvotes: 0
Reputation: 470
I ran into this. Copying some directories didn't work. Copying files did. It turned out to be because files contained in .gitignore (not just .dockerignore) are also ignored. See: https://github.com/zeit/now/issues/790
Upvotes: 2
Reputation: 380
I just experienced this problem and none of the suggestions here solved my problem. Turns out I had the wrong line endings in my file, and had to change them to the appropriate line endings. (In this case from CRLF to LF, so Ubuntu 14.04 would recognize the script, which I had been editing on windows.)
I changed the line endings using VSCode, and most code editors should have the option of choosing line endings.
Hope this helps someone.
Upvotes: 15
Reputation: 4931
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/
Upvotes: 2
Reputation: 6768
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.
Also the command for building the Dockerfile
should be something like.
cd into/the/folder/
docker build -t sometagname .
Upvotes: 55
Reputation: 1477
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
Upvotes: 1
Reputation: 7560
Do check the .dockerignore
file too.
I know this is a very rare case, but I had that file mentioned there.
Upvotes: 480
Reputation: 11
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.
Upvotes: 1
Reputation: 1748
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.
Upvotes: 1
Reputation: 31
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(...)
Upvotes: 1
Reputation: 1032
For following error,
COPY failed: stat /<**path**> :no such file or directory
I got it around by restarting docker service.
sudo service docker restart
Upvotes: 1
Reputation: 181
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.
Upvotes: 7
Reputation: 901
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.
Upvotes: 65