Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rkevinburton opened this issue Sep 26, 2017 · 38 comments
Closed

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

rkevinburton opened this issue Sep 26, 2017 · 38 comments

Comments

@rkevinburton
Copy link

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.):

@thaJeztah
Copy link
Member

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.

@daytonpa
Copy link

daytonpa commented Oct 2, 2017

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.

@rkevinburton
Copy link
Author

rkevinburton commented Oct 2, 2017 via email

@daytonpa
Copy link

daytonpa commented Oct 3, 2017

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

@thaJeztah
Copy link
Member

thaJeztah commented Oct 3, 2017

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

@leobuskin
Copy link

leobuskin commented Oct 9, 2017

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

@zh794390558
Copy link

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

@AshtonHylton-awin
Copy link

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.

@thaJeztah
Copy link
Member

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 (.)

@ramphub
Copy link

ramphub commented Nov 24, 2017

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\to\docker\file\Dockerfile

@rajiv180984
Copy link

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

@l3m
Copy link

l3m commented Jan 5, 2018

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.

@comm1x
Copy link

comm1x commented Jan 18, 2018

Check .dockerignore

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

@MahadevDevops
Copy link

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

@adsl99801
Copy link

COPY only able copy it's subfolder .

@calasyr
Copy link

calasyr commented Mar 19, 2018

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.

@btmurrell
Copy link

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

@frostyandy2k
Copy link

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.

@thaJeztah
Copy link
Member

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.

@abdasgupta
Copy link

@frostyandy2k 's answer solved the problem

NicolePell added a commit to NicolePell/multi-docker that referenced this issue Oct 11, 2018
@renepardon
Copy link

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!

@hanlina0737
Copy link

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

@ZhuangyiZhao
Copy link

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.

@DrJimFan
Copy link

dockerignore is the fix!! thanks

@alp1204ca
Copy link

Check .dockerignore

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

Thanks comm1x! That solved my problem!

@GusAntoniassi
Copy link

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/"]

@laybycity
Copy link

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

@Pi-George
Copy link

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

@loko35387417
Copy link

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?

@iotnxt-build
Copy link

dockerignore is the fix!! thanks

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

@mldisibio
Copy link

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

myproject
│   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" ]

@ahmedbokhari7
Copy link

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

@thaJeztah
Copy link
Member

@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/

@elmawardy
Copy link

In my case it was a typo in the filename

@amirali-alation
Copy link

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.

@agkrishna101
Copy link

agkrishna101 commented Sep 7, 2020

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

@urssanj00
Copy link

For me, it was happening due to wrong path of local file.. and it took 30 minutes to realize .. lol

@thaJeztah
Copy link
Member

I'm locking the conversation on this thread, as it looks like it's only collecting "this happened to me too" comments; #34986 (comment)

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.

Since that this issue was reported, some improvements have been made in the error messages to make them less confusing (shipped as part of docker 20.10.x)

In Docker 20.10, errors for missing (or excluded) files look like;

[+] Building 0.9s (6/9)
 => [internal] load build definition from Dockerfile                0.2s
 => => transferring dockerfile: 306B                                0.0s
 => [internal] load .dockerignore                                   0.1s
 => => transferring context: 2B                                     0.0s
 => [internal] load metadata for docker.io/library/alpine:latest    0.0s
 => CACHED [1/5] FROM docker.io/library/alpine                      0.0s
 => [internal] load build context                                   0.6s
 => => transferring context: 701B                                   0.5s
 => ERROR [2/5] ADD no-such-file.txt /                              0.0s
------
 > [2/5] ADD no-such-file.txt /:
------
failed to compute cache key: "/no-such-file.txt" not found: not found

And there's a tracking issue to improve output to distinguish "non-existing" files from "files that are excluded by .dockerignore; moby/buildkit#1647 (subscribe to that ticket to stay informed on progress)

@moby moby locked as resolved and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests