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
)
Your comment
# fails on this line
is the problem. As per the Docker documentation:More info here: https://docs.docker.com/engine/reference/builder/#format