Moby: COPY failed: stat /var/lib/docker/tmp/docker-builder918577595/...

Created on 26 Sep 2017  Â·  36Comments  Â·  Source: moby/moby

Description

I have a Dockerfile that has the line:

COPY MyAgSourceAPI/conf/php/testsql.php /var/www/

But it causes the error:

COPY failed: stat /var/lib/docker/tmp/docker-builder918577595/MyAgSourceAPI/conf/php/testsql.php: no such file or directory

Steps to reproduce the issue:

  1. Create a Dockerfile
  2. docker build -t rkevinburton/myagsourceapi .

Describe the results you received:

COPY failed: stat /var/lib/docker/tmp/docker-builder918577595/MyAgSourceAPI/conf/php/testsql.php: no such file or directory

Describe the results you expected:

I would expect the file to be copied.

Additional information you deem important (e.g. issue happens only occasionally):
I have two lines previous to this one:

COPY MyAgsourceAPI/conf/apache/conf.d/myagsource.conf /etc/apache2/conf.d/myagsource.conf
COPY MyAgsourceAPI/conf/apache/sites-available/default.conf /etc/apache2/sites-available/default.conf

They copy a single file and both runs without error.

This seems similiar to issues raised on for-mac and for-linux repositories but the solution (correct .dockerignore) does not seem applicable since this file does not exist.

Output of docker version:

PS C:\Users\rburton\code> docker version
Client:
 Version:      17.06.2-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 19:57:19 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.06.2-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   cec0b72
 Built:        Tue Sep  5 19:59:19 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

PS C:\Users\rburton\code> docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 5
Server Version: 17.06.2-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan 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: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.41-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: moby
ID: 4ZGZ:VUUY:PSMN:56QB:GSTL:FAYH:J326:YZW3:ZQ5U:63UZ:TIIT:QSTR
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 16
 Goroutines: 26
 System Time: 2017-09-26T13:26:23.281243Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

arebuilder statumore-info-needed versio17.06

Most helpful comment

Check .dockerignore

You probably trying to copy files that are in .dockerignore.

All 36 comments

Does the file MyAgSourceAPI/conf/php/testsql.php exist in the path where you're starting the build from? If you think it's a bug, can you provide the exact steps to reproduce? Keep in mind that we don't have access to your build environment, so cannot reproduce the steps you've written so far (i.e., we don't have access to your Dockerfile, or the files you're using in your Dockerfile.

I'm running into this too. I have all of the files I want to copy in /var/lib/docker/[storage directory] and am running the docker build command from inside that directory.

I have a config.json file inside the /var/lib/docker/[storage directory], and I get this output:

Step 20/27 : COPY /config.json /.berkshelf/config.json STDERR: COPY failed: stat /var/lib/docker/tmp/docker-builder836544169/config.json: no such file or directory ---- End output of docker build --file ./Dockerfile.jenkins --tag docnetwork-scruffy-ci . ----

It looks like Docker is creating a new /tmp/docker-builderxxxxxxx..../ directory on top of the directory you're building from, and then cannot reference the files I wish to copy.

I have seemed to reach the conclusion that this error happens not only when the source file is missing but also when the permissions on the destination path will not allow access. Does this match your experience?

I am currently performing all actions as root. Even after running a sudo usermod -aG docker my_user on my user following the installation of Docker, I still receive the error.

Step 19/27 : RUN mkdir /.ssh && mkdir /.aws && mkdir /.berkshelf
        ---> Running in 05240f357302
        ---> 2491c79e79c6
       Removing intermediate container 05240f357302
Step 20/27 : COPY ./config.json /.berkshelf/config.json
       STDERR: COPY failed: stat /var/lib/docker/tmp/docker-builder124447013/config.json: no such file or directory

In case I didn't list before:

vagrant@default-ubuntu-1604:~$ docker -v
Docker version 17.09.0-ce, build afdb6d4

vagrant@default-ubuntu-1604:~$ uname -a
Linux default-ubuntu-1604 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

I'm running into this too. I have all of the files I want to copy in /var/lib/docker/[storage directory] and am running the docker build command from inside that directory.
I have a config.json file inside the /var/lib/docker/[storage directory], and I get this output:

I would be _very_ cautious using any directory inside /var/lib/docker as your build context; that directory holds all the state/containers/images/volumes that are managed by the daemon, and making changes to those files could lead to odd behaviour (some directories may also be mounted/unmounted when starting containers.

Can you provide the minimal steps to reproduce, not depending on your environment or custom (private) images, e.g.

mkdir foo && cd foo
echo '{"hello":"world"}' > config.json

docker build -t testing . -f -<<EOF
FROM alpine
COPY ./config.json /.berkshelf/config.json
EOF

Same problem. The funniest moment - everything was fine few iterations before. Looks like it got broken after COPY . /some_internal_path [it was the last successful try during this container development] (built via docker-compose with changed context)

I don't know how to reproduce it, to be frankly. It's broken now and I cannot find a solution to get it back to work at all.

> Docker version 17.09.0-ce, build afdb6d4
> Linux * 4.10.0-35-generic #39-Ubuntu SMP Wed Sep 13 07:46:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Does MyAgSourceAPI/conf/php/testsql.php exists in you current dir?
All resources must exist in docker build PATH, see below:

Usage: docker build [OPTIONS] PATH | URL | -

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.

Running docker build docker/development/Dockerfile will use docker/development/Dockerfile as its build-context; any file referenced from the Dockerfile will need to be inside that path. Whereas docker build . -f docker/development/Dockerfile uses . (first argument) as build context, and loads the Dockerfile from docker/development/Dockerfile as if it was located at the root of the build-context (.)

I have similar issue on Windows.

COPY failed: stat /var/lib/docker/tmp/docker-builder746346263/xyz.properties

it did not help to use -f option. I tried same directory as the Dockerfile both by giving relative path as well as qualified path to the docker file as -f D:\path\todocker\fileDockerfile

Following working for me perfectly.
I faced this issue, I was not able to copy zeppelin [1GB] directory into docker conatiner. and getting issue "COPY failed: stat /var/lib/docker/tmp/docker-builder977188321/zeppelin-0.7.2-bin-all: no such file or directory"

I am using docker Version: 17.09.0-ce and resolved issue by following steps.
Step 1: copy zeppelin directory [which i want to copy into docker package]into directory contain "Dockfile" 
Step 2: edit Dockfile and add command [location where we want to copy]
ADD ./zeppelin-0.7.2-bin-all /usr/local/  
Step 3: go to directory which contain DockFile and run command [alternatives also available]
docker build .

Step 4:  docker image created Successfully with logs
Step 5/9 : ADD ./zeppelin-0.7.2-bin-all /usr/local/
 ---> 3691c902d9fe
Step 6/9 : WORKDIR $ZEPPELIN_HOME
 ---> 3adacfb024d8 ....
Successfully built b67b9ea09f02

I had the same problem on CentOS 7. It seems it's related to either filename or filename length.

I had the problem with the filename: node-v6.11.0-linux-x64.tar.xz
It worked with the filename: node.tar.xz

It was the same file, I just renamed it.

This might help find the bug.

Check .dockerignore

You probably trying to copy files that are in .dockerignore.

I have the same problem in linux but it worked for me specifying COPY ./filename /usr/local....

COPY only able copy it's subfolder .

My mistake was thinking if I explicitly copy a single file, .dockerignore would not be used to filter that instruction. Not so. You cannot COPY a single file in a directory of a million files that you otherwise want to ignore. .dockerignore applies to every COPY command.

thanks to pointing out the context issue @AshtonHylton-awin and @thaJeztah -- that was the answer for me. For those of you using docker-compose.yml this type of block will do the equivalent of the docker build commands referenced above:

        build:
            context: .
            dockerfile: ./postgres/Dockerfile

Always check .dockerignore. I got a project from a third party and it included '*'. No wonder i couldn't copy anything from the context. Thanks @comm1x for pointing it out.

Reading through this issue, I don't think there's a bug at hand here, so I'll go ahead and close.

If you _do_ think there's still a bug after reading through this issue, please open a new ticket with the exact steps to reproduce.

@frostyandy2k 's answer solved the problem

Check .dockerignore

You probably trying to copy files that are in .dockerignore.

That solved my problem! I had the docker folder within .dockerignore but some files within this folder should be copied to the final image. Thank you for this advice!

I have the same question and I try to issue serval ways but it stlls exists

I noticed this:
I moved the current directory to /work_dir, and I changed the directory to /work_dir. Then I can copy from ./data/example/file.txt successfully. But I was not able to do it using the absolute path, like cp /work_dir/data/example/file.txt.

dockerignore is the fix!! thanks

Check .dockerignore

You probably trying to copy files that are in .dockerignore.

Thanks comm1x! That solved my problem!

In my case it was a missing coma from the COPY instruction:

COPY ["Dockerfile", "main.py", "requirements.txt", "src" "/app/"]

Adding a comma after "src" fixed the problem:

COPY ["Dockerfile", "main.py", "requirements.txt", "src", "/app/"]

I Manged to go around this by exclusing the folder directive since i was only trying to copy a folder within the working directory i was able to use ( . ) and the url path i.e

I'm just trying COPY /etc/group /tmp/group and getting this issue

my net is slowly so I want to copy my local composer to php container.
composer: /var/www/docker/script/composer
dockerfile /var/www/docker/php/Dockerfile
RUN ../../script/composer /usr/local/bin/

COPY failed: Forbidden path outside the build context: ../../../script/composer
I change code in Dockerfile
WORKDIR /var/www/docker/script
COPY composer /usr/local/bin
Its fine.

So it is build context probile?

dockerignore is the fix!! thanks

Thank you for this comment. I've been struggling for 3 hours, and this made me think, just maybe...

If it can be of help, in my case it was trying to execute a COPY operation as if the context was Dockerfile, but context needed to be docker-compose one level up:
Given this directory structure

│   docker-compose.yml
│
└───src
    │   Dockerfile
    │
    └───publish
            my.app.dll

if I were building just from Dockerfile I would have:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
WORKDIR /app
COPY publish/ .
ENTRYPOINT [ "dotnet", "my.app.dll" ]

but when building from docker-compose which sets the build context as '.' and the dockerfile as src/Dockerfile
then the Dockerfile must reflect the docker-compose context

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
WORKDIR /app
COPY src/publish/ .
ENTRYPOINT [ "dotnet", "my.app.dll" ]

when i build my docker file i get this error althoughh target folder is there in my project
can some plz help
''''''''''''''''''''''''''''''''''''''''''''''''''
sending build context to Docker daemon 84.99kB
Step 1/7 : FROM openjdk:8-jdk-alpine
---> a3562aa0b991
Step 2/7 : VOLUME /tmp
---> Using cache
---> c8ca5e3ac388
Step 3/7 : ARG DEPENDENCY=target/dependency
---> Using cache
---> 1a1a2a4a5db1
Step 4/7 : COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY failed: stat /var/lib/docker/tmp/docker-builder997333669/target/dependency/BOOT-INF/lib: no such file or directory

@ahmedbokhari7 if you set the context: in your compose-file, both should work; see https://docs.docker.com/compose/compose-file/#context

in your case, context should probably be set to context: ./src/

In my case it was a typo in the filename

I had this problem but I solved it based on the comments of @thaJeztah. Please note that the path starts from where you start the build and not from where your Dockerfile is located. So you need to bear that in mind when writing the path in your Dockerfile and use COPY or ADD.

I was trying to create docker image using "docker build -t reimage17 ." command. I am getting an error as below while copying the "oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm" file from basicinstaclient folder to basic folder.
Step 7/9 : ADD ./basicinstaclient/oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm /basic/
ADD failed: stat /var/lib/docker/tmp/docker-builder925234299/basicinstaclient/oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm: no such file or directory.

I am executing build command from folder where docker file exist in my windows machine. below is my docker file.

FROM ibmcom/websphere-liberty:latest
USER root

ADD ./rtcc.ear /opt/ibm/wlp/usr/servers/defaultServer/apps
ADD ./rtccClient.war /opt/ibm/wlp/usr/servers/defaultServer/apps
RUN yum -y install libaio

RUN mkdir -pv /basic
COPY ./basicinstaclient/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm /basic/
RUN rpm -i /basic/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm

EXPOSE 9088
please help

Was this page helpful?
0 / 5 - 0 ratings