docker / for-mac

Bug reports for Docker Desktop for Mac
https://www.docker.com/products/docker#/mac
2.43k stars 118 forks source link

/var/lib/docker/tmp/docker-builderXXXXXXX/... no such file or directory #1922

Closed bjcatar closed 5 years ago

bjcatar commented 7 years ago

Expected behavior

COPY command to copy a file from local to image

Actual behavior

doing a simple COPY command in Dockerfile is throwing this error when the file is in a folder (not same level as Dockerfile file)

Information

Docker for Mac: version: 17.06.0-ce-mac19 (4cdec4294a50b2233146b09469b49937dabdebdd) macOS: version 10.12.6 (build: 16G29) logs: /tmp/04FF32A9-CA64-40EB-B0DC-AD3E13A6C7D5/20170731-232145.tar.gz [OK] db.git [OK] vmnetd [OK] dns [OK] driver.amd64-linux [OK] virtualization VT-X [OK] app [OK] moby [OK] system [OK] moby-syslog [OK] db [OK] env [OK] virtualization kern.hv_support [OK] slirp [OK] osxfs [OK] moby-console [OK] logs [OK] docker-cli [OK] menubar [OK] disk

FROM python:latest RUN apt-get update RUN apt-get install nano RUN mkdir /code WORKDIR /code COPY /helpdesk/requirements.txt /code/

Steps to reproduce the behavior

  1. docker build -t test .
huoyuxin commented 4 years ago

set right path when you run docker-cli: docker build [OPTIONS] PATH | URL | - eg: docker build -f deploy/Dockerfile .

Najmeh-M commented 4 years ago

docker build . -f dockerfile

worked for me :)

davidjguru commented 4 years ago

Hello, the change: docker build . -f Dockerfile proposed in: https://github.com/docker/for-mac/issues/1922#issuecomment-492919359

Worked for me! :-D

MikeAlhayek commented 4 years ago

I had the same problem with using Visual Studio 2019 and Windows 7. My Dockerfile was generated by Visual Studio. Since the Dockerfile was at the project level (next to my .csproj file), paths were wrong. I moved the Dockerfile one level up so it is in the same folder as the solution (.sln) file, and run the build everything worked as expected.

faekz0r commented 4 years ago

Have a fix.

Here is what my original code looks like: COPY /TestCode TestCode/

I decided to try this and it magically worked:

WORKDIR /TestCode

COPY . TestCode/

Tried most of the other solutions here so this might work for other people as well.

Tried all the solutions. Nothing worked besides this one.

jay-hankins commented 4 years ago

Hi @faekz0r, just wanted to let you know that there's actually a subtle difference between your original code and the working code. In this case, I think the "no such file or directory" error was probably correct.

In the first version, COPY /TestCode TestCode/, you are asking Docker to copy files from the host /TestCode directory to the container TestCode/ (note, this becomes /TestCode/ because the container FS is /).

In the second version, two things are happening:

  1. WORKDIR /TestCode tells Docker that all further commands are to consider /TestCode as the current working directory on the container. Again, the default working directory is /.
  2. COPY . TestCode/ tells Docker that you want to copy files from the host current working directory (the files next to your Dockerfile) into the $WORKDIR/TestCode/ directory on the container.

To learn more, you can docker exec into a shell (if your image includes one), and explore the container's filesystem for yourself.

faekz0r commented 4 years ago

Okay @jay-hankins. Even tho my Dockerfile was slightly different (was using full path for the COPY destination), can you explain why COPY /TestCode/full/path /TestCode/different/full/path was not working, but with WORKDIR /TestCode/full/path and COPY . /TestCode/different/full/path it was working? :P

jay-hankins commented 4 years ago

Sure @faekz0r. So the difference lies in the first argument to the COPY instruction.

COPY /TestCode/full/path <whatever> vs. COPY . <whatever>

The first argument is from the perspective of the host. If you have a Linux system, you will have some common directories like /var, /etc, and more. Run ls -al / to see everything in your host's root directory.

With the first approach, you are asking Docker to COPY files at /TestCode/full/path on the host. If there's no TestCode directory in your root, this command will fail because the path is not valid. Confirm with ls -al /.

With the second approach, you are asking Docker to COPY files at . on the host. ., of course, is the current working directory from which you are running the docker build command. Before running docker build, run pwd. That will tell you what the value of . is. It's probably something like /home/you/your_project.

faekz0r commented 4 years ago

But the . and the /TestCode/full/path are exactly the same, since WORKDIR = /TestCode/full/path. Or am I missing something?

lucasbasquerotto commented 4 years ago

@faekz0r WORKDIR defines the directory in the container to be the path in which you enter and execute commands (unless another command changes the directory).

The 1st argument after COPY in COPY /TestCode/full/path <whatever>, that is, /TestCode/full/path, is the path in the host (your machine, outside the container), starting from the docker build context (that by default is where your Dockerfile is).

When you run docker build -t hello-demo-app . the context is your current directory (see the . in the command). If you run docker build -t hello-demo-app .. the context is the parent directory (this might break .dockerignore). You can also define it in context (inside build) in a docker-compose.yml file.

So, unless you have a TestCode directory in your build context (in your machine), you will receive an error.

nekar93 commented 4 years ago

I found an error... i don't know if is THE ERROR but this surely doesn't work.

Dockerfile

FROM tomcat:8.5
COPY api/build/libs/api.war /usr/local/tomcat/webapps/

This is the file:

ls -la api/build/libs/api.war 
-rw-r--r-- 1 root root 42605790 Feb  6 00:05 api/build/libs/api.war

When i run docker build -t image-try:0.0.1 . it dies badly...

So i copy my api.war in the pwd and change Dockerfile in:

FROM tomcat:8.5
COPY api.war /usr/local/tomcat/webapps/

and it WORK.

So, I investigated thoroughly and i observe that if i rename the build folder in any other way, the docker build will work.

Therefore the problem is the build folder in the path to be COPY.

It is possible? anyone other can confirm my doubt/solution?

winkee01 commented 4 years ago

make sure you don't have any comment stuff trailing the line

svenmuellerssen commented 4 years ago

I just had this problem, although I could copy some files and not others. Turned out that I had a parent directory excluded in .dockerignore and a directory I renamed was no longer being explicitly allowed.

I had the same issue being able to copy some folders but not others. It was exactly the same solution. I "ignored" the folders I was not able to copy. :-D

Wapiti08 commented 4 years ago

check your .dockerignore. Maybe you made a mistake here.

dralshehri commented 4 years ago

I got this error when I moved my Dockerfile to a subfolder, and kept docker-compose.yml at root.

To fix it, I had to change any source path in Dockerfile to be relative to the path of build context in docker-compose.yml not to the path of Dockerfile

amit4440 commented 4 years ago

Have a fix. Here is what my original code looks like: COPY /TestCode TestCode/ I decided to try this and it magically worked:

WORKDIR /TestCode

COPY . TestCode/

Tried most of the other solutions here so this might work for other people as well.

Tried all the solutions. Nothing worked besides this one.

rmanansa commented 4 years ago

Here's the same problem I encountered and how I solved this once and for all.

FROM adoptopenjdk/openjdk11:alpine
MAINTAINER XXX XXX <ramil.xxxxx@xxxx.ai>

# Add the service itself
ARG JAR_FILE="myservice-1.0.0.jar"
RUN apk add maven
WORKDIR /app
COPY . /app/
RUN mvn -f /app/pom.xml clean install -DskipTests
WORKDIR /app
COPY target/${JAR_FILE} /usr/share/${JAR_FILE}

ENTRYPOINT ["java", "-jar", "/usr/share/myservice-1.0.0.jar"]

This is generating the same error of not finding the jar file in the default Docker location /var/lib/docker/tmp/docker-builderXXXXXX. I got a suggestion from someone at StackOverflow and I was able to make it work with changing this culprit line from above with the below.

RUN cp target/${JAR_FILE} /usr/share/${JAR_FILE}

Then another solution to this I found by doing more research in the other Docker and Springboot forums that if you copy from the Original container of a multi-stage build then you can actually find that WORKDIR target folder location as you name it. The name you use in the First stage container will be searchable in the Second-stage container. This is better since it's 5x smaller image than the one you build with above single-stage Dockerfile. You can find my multi-stage solution here at StackOverflow. You can find the package in the folder name you specify.

https://stackoverflow.com/questions/60573551/copy-or-add-command-in-dockerfile-fails-to-find-jar-file-for-springboot-applicat/60593637#60593637

ahmedbokhari7 commented 4 years ago

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

TadejTastro commented 4 years ago

I had to use the following command for building and it worked:

docker build .

docker-robott commented 4 years ago

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked