【问题标题】:Unable to build docker image with Jenkinsfile无法使用 Jenkinsfile 构建 docker 映像
【发布时间】:2021-06-01 15:51:16
【问题描述】:

从这个https://www.jenkins.io/doc/book/pipeline/docker/我想传递一个特定的dockerfile路径。

$jenkins_home/workspace/<project>下的目录结构

├── dockerfiles
    ├── hello
    │   └── Dockerfile
├── Jenkinsfile

jenkinsfile 中的内容是这样的

stage('Build Image') {
            steps {
                script {
                    def dockerfile = "Dockerfile.${env.branchName}"
                    def dockerImage = docker.build("${imageName}" + ":" + "${imageTag}", "-f ${dockerfile} ./dockerfiles")
                }
            }
        }

导致这个错误

+ docker build -t localhost:32000/hello:feature -f Dockerfile.hello ./dockerfiles
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/jenkins_home/workspace/simple_project/Dockerfile.hello: no such file or directory

【问题讨论】:

  • 就像错误消息说的那样,它不喜欢符号链接,特别是出于安全原因,指向当前目录之外的任何内容的符号链接。
  • @BTH.S3 我提供的解决方案对你有用吗

标签: docker jenkins jenkins-pipeline jenkins-groovy


【解决方案1】:

看来Dockerfile.hello 不在所述的具体路径中。

docker build -t localhost:32000/hello:feature -f Dockerfile.hello ./dockerfiles

如果您的 Dockerfile 在另一个目录/文件夹中,那么您需要明确指定目录:

因此,如果您在 "/dockerfiles/hello" 目录中存在 Dockerfile,您将从 Jenkinsfile 传递为:

 def dockerImage= docker.build("${imageName}" + ":" + "${imageTag}", "./dockerfiles/hello")

从位于 ./dockerfiles/hello/Dockerfile 的 Dockerfile 构建映像。

【讨论】:

    猜你喜欢
    • 2021-12-24
    • 1970-01-01
    • 2022-10-23
    • 2020-05-21
    • 2021-03-17
    • 2021-10-17
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多