ADD failed: stat /var/lib/docker/tmp/docker-builderXXXXXX: no such file or directory
- [x] This is a bug report
- [ ] This is a feature request
- [x] I searched existing issues before opening this one
Expected behavior
COPY/ADD should work with absolute paths
Actual behavior
An error occur when trying to ADD/COPY with an absolute path
Sending build context to Docker daemon 90.62kB
Step 1/2 : FROM alpine:latest
---> 02674b9cb179
Step 2/2 : ADD /tmp /tmp
ADD failed: stat /var/lib/docker/tmp/docker-builder310665597/tmp: no such file or directory
Steps to reproduce the behavior
FROM alpine:latest
ADD /tmp /tmp # COPY fails too
Output of docker version:
Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 3dfb8343
Built: Wed Jul 26 18:03:33 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 02c1d87617
Built: Wed Jul 26 20:03:39 2017
OS/Arch: linux/amd64
Experimental: false
Output of docker info:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 162
Server Version: 17.06.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 316
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.12.7-1-MANJARO
Operating System: Manjaro Linux
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15.6GiB
Name: mauri870-pc
ID: 7CHC:HTHK:NHE6:EF7M:F4SU:2GNG:SGX4:XGFG:FSKF:26LD:O5YX:H5GN
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional environment details (AWS, VirtualBox, physical, etc.) Physical. Seems to be related with https://github.com/docker/for-mac/issues/1922
Paths in a Dockerfile are always relative to the the context directory. The context directory is the positional argument passed to docker build (often .).
If there is no ./tmp in the context directory then this is the expected behaviour.
@dnephin This behavior has been introduced recently? Because I remember using absolute paths in my Dockerfiles without problems 😕
I believe it has always been this way.
Thanks for your help @dnephin
Why is the context still in the tmp folder when I specified the actual path and not .?
@janmchan I had exactly the same problem with dotnet and docker. Turned out that the directory I was trying to COPY was ignored by .dockerignore (which in turn was generated by dotnet itself). Once I changed .dockerignore, everything worked.
@qbikez, how did you change the .dockerignore file? I have it like this:
*
!obj/Docker/empty/
and is still giving the same copy error
@netspark Mine looks like this:
*
!obj/Docker/publish/*
!obj/Docker/empty/
So everything besides obj/Docker/publish/* and obj/Docker/empty/ is ignored. By default, the generated Dockerfile does:
COPY ${source:-obj/Docker/publish} .
So it copies from a directory that's not ignored and everything is fine. But, if in your Dockerfile you have a COPY that uses any other directory, like COPY bin/Debug/netcoreapp2.0/ . (or if you set source arg to something else), then docker will say "no such file or directory", because bin/Debug/netcoreapp2.0/ is ignored (thanks to the wildcard * in .dockerignore.
If you're unsure of what is ignored or is this the cause at all, you can just try and remove .dockerignore. Docker may build a little slower, but there will be one moving part less to worry about.
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 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.
I'm getting same behavior from COPY ./pytorch /app/pytorch
I am trying to copy ~/.ssh/id_rsa to my container. Below is how my dockerfile looks line
FROM openjdk:8u171 AS init
VOLUME /root/.ssh
ADD ~/.ssh/id_rsa /root/.ssh
RUN echo $(ls /root/.ssh)
RUN echo "StrictHostKeyChecking no " > /root/.ssh/config
I get a similar error : ADD failed: stat /var/lib/docker/tmp/docker-builder898806991/~/.ssh/id_rsa: no such file or directory
I'm having the same error.
Same Error
same Error
Same with both relative or not paths
if you have .dockerignore file in folder, you should be add **/directoryFile
Dockerfile nginx `FROM nginx:1.10
ADD ./docker-compose/nginx/vhosts.conf /etc/nginx/conf.d/default.conf`
.dockerignore
**/docker-compose
I too had same error. Since I had many dockerfiles in the directory I was giving the file:
$ sudo docker build -t image-name:version - < test3.dockerfile
This used to give the the following error:
COPY failed: stat /var/lib/docker/tmp/docker-builder132607663/xxx/xxxx: no such file or directory
Afterwards, I change my dockerfile name to Dockerfile and built it by:
$ sudo docker build -t image-name:version .
This worked! The path of the file to be copied was right (relative path) from the start. Second time it worked and the first time it didn't work.
So changing the name from test3.dockerfile to Dockerfile and running the second command removes the error.
@csbenk in your case, the issue you were having is due to the syntax you used; depending on the syntax when piping a dockerfile to stdin, the context is sent, or not;
Set up the test directory, and make some files;
mkdir test && cd test
touch one two three four
Create a Dockerfile
cat <<EOF>Dockerfile
FROM busybox
COPY . /files
EOF
Build (with the Dockerfile from stdin) using -
This syntax takes the Dockerfile from stdin, but no build-context (so no files are sent to the daemon to be used during build);
cat ./Dockerfile | docker build -t bla -
Once the build completes; run the image, and notice that no files were added;
docker run --rm bla ls -la /files
total 8
drwx------ 2 root root 4096 Nov 13 18:04 .
drwxr-xr-x 1 root root 4096 Nov 13 18:10 ..
Build (with the -f flag and - with a Dockerfile from stdin)
This syntax is slightly different; the build in the example below uses the following arguments
-t bla2name/tag for the image-fuse a custom Dockerfile (instead of a file namedDockerfilein the current directory)-the custom Dockerfile will be piped tostdin, not from a file.use the current (.) directory as build-context, and send any file present to the daemon to be used during build
cat ./Dockerfile | docker build -t bla2 -f- .
Once the build completes; run the image, and notice that the files were added;
docker run --rm bla2 ls -la /files
total 12
drwx------ 2 root root 4096 Nov 13 18:11 .
drwxr-xr-x 1 root root 4096 Nov 13 18:11 ..
-rw-r--r-- 1 root root 27 Nov 13 18:10 Dockerfile
-rw-r--r-- 1 root root 0 Nov 13 18:03 four
-rw-r--r-- 1 root root 0 Nov 13 18:03 one
-rw-r--r-- 1 root root 0 Nov 13 18:03 three
-rw-r--r-- 1 root root 0 Nov 13 18:03 two
Thanks for the detailed explanation @thaJeztah
You're welcome! There was an issue for improving the docs around this (https://github.com/docker/docker.github.io/issues/3538); and improvements were made in https://github.com/docker/docker.github.io/pull/6807, but if you have suggestions how to improve the documentation, that would be welcome
/cc @ahh-docker