簡體   English   中英

無法使用 Jenkinsfile 構建 docker 映像

[英]Unable to build docker image with Jenkinsfile

從這個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

看起來Dockerfile.hello不在提到的特定路徑中。

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

如果您的 Dockerfile 在另一個目錄 /folder 中,那么您需要明確指定目錄:

因此,如果您在"/dockerfiles/hello"目錄中存在Dockerfile ,您將從 Jenkinsfile 傳遞為:

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

從位於 ./dockerfiles/hello/Dockerfile 的 Dockerfile 構建映像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM