3

There are many other questions about this issue, and I've looked at every resource I can find in a google search about this error message, but none of them have worked for me.

I'm using a Jenkins job to automate the build/push of a container. To do so, I'm using the "Execute Shell" build step, and doing all of my Docker configuration within (I've tried using a pipeline, but those just don't work in my team's Jenkins configuration; consider them outside the scope of this question). The job first clones a git repository (myrepo), and then I have a shell script write a number of files that I want to include in the Docker container (e.g. run.sh), as well as a Dockerfile.

The folder structure of my Jenkins workspace is as follows, by the time the build fails:

|-- myrepo/
|   |-- myexe            # executable file
|   |-- testfiles/
|   |   |-- file1.txt
|   |   |-- file2.txt
|   |   |-- ...
|-- run.sh
|-- Dockerfile

I do not have a .dockerignore file.

The Dockerfile, by the time the build fails, looks like this:

FROM centos
USER root
# create directories
RUN mkdir -p /opt/dir1/myexe
# copy shell script
COPY run.sh /usr/bin/runprog
# copy executable
COPY myrepo/myexe /opt/dir1/myexe/       # fails on this line
COPY myrepo/testfiles /opt/dir1/myexe/
# final setup 
WORKDIR /opt/dir1/myexe/
CMD ["/opt/dir1/myexe/myexe"]

Now, on Jenkins, I'm executing this all in the "Execute Shell" build step, after having imported the repo earlier. I create run.sh and Dockerfile during this step, using echo and output redirection. The shell script being executed in Jenkins's "Execute Shell" build step looks something like this:

echo '#!/bin/sh
...
' > run.sh

echo 'FROM centos
...
' > Dockerfile

docker system prune -af
docker images           # I can confirm from logs that no images remain
docker build -t containername:${DOCKER_IMAGE_TAG} .

But when I run this, the build fails on that docker build command:

Step 5/8 : COPY myrepo/myexe /opt/dir1/myexe
COPY failed: stat /var/lib/docker/tmp/docker-builder190297994/opt/dir1/myexe: no such file or directory

None of the other questions I've seen have solutions that have helped. My files exist locally, which I can see in the Jenkins workspace after the build fails. My files exist locally in the . directory, which I can confirm by putting pwd and ls just before the docker build command. I don't have a .dockerignore file, so Docker shouldn't be ignoring anything. But I must be missing something, as it's still not working no matter what I think to try.

What am I overlooking?

(Docker version is Docker version 18.09.7, build 2d0083d)

mchawre
  • 10,744
  • 4
  • 35
  • 57
Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53
  • Have you tried placing the files/dirs you copy in the same directory as your `Dockerfile`? In other words, try `cd ; cp myrepo/myexe ./` I know that Dockerfiles cannot use `COPY` for files/dirs outside of your `Dockerfile`'s directory, I am not sure if that also applies for subdirectories in your Dockerfile dir, hence my suggestion. – Perplexabot Jul 03 '19 at 16:28
  • 2
    I have tried that, in fact (did `cp myrepo/myexe myexe` and then did `COPY myexe ...` in the dockerfile). It didn't work, unfortunately – Green Cloak Guy Jul 03 '19 at 16:29
  • Have you tried running the Dockerfile in a standalone environment? Without auotmatically creating it (but typing it yourself), without Jenkins. Hey! I got the same error running the exact copy of your `Dockerfile`. Interesting. – Perplexabot Jul 03 '19 at 16:38
  • 1
    Dude! I removed your comment `# fails on this line` and everything worked. Remove it and try again!!!! – Perplexabot Jul 03 '19 at 16:44

1 Answers1

5

Your comment # fails on this line is the problem. As per the Docker documentation:

Docker treats lines that begin with # as a comment, unless the line is a valid parser directive. A # marker anywhere else in a line is treated as an argument.

More info here: https://docs.docker.com/engine/reference/builder/#format

Perplexabot
  • 1,852
  • 3
  • 19
  • 22