有many other questions about this问题,我查看了在谷歌搜索中可以找到的有关此错误消息的所有资源,但没有一个对我有用。
我正在使用 Jenkins 作业来自动构建/推送容器。为此,我使用“执行 Shell”构建步骤,并在其中执行所有 Docker 配置(我尝试使用管道,但这些在我团队的 Jenkins 配置中不起作用;请在这个问题的范围)。该作业首先克隆一个 git 存储库 (myrepo
),然后我用一个 shell 脚本编写一些我想要包含在 Docker 容器中的文件(例如 run.sh
) >),以及 Dockerfile。
构建失败时,我的 Jenkins 工作区的文件夹结构如下:
|-- myrepo/
| |-- myexe # executable file
| |-- testfiles/
| | |-- file1.txt
| | |-- file2.txt
| | |-- ...
|-- run.sh
|-- Dockerfile
我没有 .dockerignore
文件。
当构建失败时,Dockerfile 看起来像这样:
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"]
现在,在 Jenkins 上,我在之前导入存储库后,在“执行 Shell”构建步骤中执行这一切。我在此步骤中使用 echo
和输出重定向创建 run.sh
和 Dockerfile
。在 Jenkins 的“执行 Shell”构建步骤中执行的 shell 脚本如下所示:
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} .
但是当我运行此命令时,构建在 docker build
命令上失败:
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
我见过的其他问题都没有提供有帮助的解决方案。我的文件存在于本地,构建失败后我可以在 Jenkins 工作区中看到这些文件。我的文件本地存在于 .
目录中,我可以通过将 pwd
和 ls
放在 docker build
命令。我没有 .dockerignore 文件,因此 Docker 不应忽略任何内容。但我一定错过了一些东西,因为无论我想尝试什么,它仍然不起作用。
我忽略了什么?
(Docker 版本为 Docker 版本 18.09.7,内部版本 2d0083d
)
最佳答案
你的评论#在这一行失败
就是问题所在。
根据 Docker 文档:
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.
更多信息请点击:https://docs.docker.com/engine/reference/builder/#format
关于docker - Jenkins-Run Docker : COPY failed: stat/var/lib/docker/tmp/docker-builder. ..:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56874246/