簡體   English   中英

使用 Jenkins 管道在 Jenkins 上構建 docker 容器

[英]Building a docker container on Jenkins using a Jenkins Pipeline

我正在嘗試在 Jenkins 服務器上構建 docker 映像,該服務器使用 COPY 命令將 a.war 文件復制到容器中。 Jenkins 無法處理以獲得 Docker 找到我想要復制到容器中的文件所需的正確構建上下文。

錯誤:

COPY failed: stat /var/lib/docker/tmp/docker-builder191966749/auth-ms-0.0.2-SNAPSHOT.war

我嘗試使用來自 Cloudbees 的 Docker 管道插件,以及自己調用docker build 這是負責構建的 Jenkinsfile 管道部分:

stage('Build Docker') {
            steps {

                script {
                
                    TAG = sh(script: "echo ${BUILD_TAG}-${env.version}", returnStdout: true)

                    dir("${buildDir}") {
                        def auth = docker.build("${env.AUTH_MS_REPO}:latest", "-f Dockerfile --build-arg ARTIFACT_NAME=\"${env.FILE}\" --build-arg EXPOSE=\"${EXPOSE}\" .")
                        auth.push()
                        auth.push("${env.AUTH_MS_REPO}:${TAG}")
                    }
            }
      }
}

我已經嘗試了所有可能的路徑組合(使用 jenkins dir() ,使用絕對和相對路徑)。 Jenkins 永遠不會在${buildDir}中找到構建上下文。

我還在服務器上手動驗證了該命令是否有效並且所有文件都存在。

您不能使用Docker在 Cloudbees 上構建圖像。 如果您查看 Cloudbees 的這篇文章,您會發現您需要使用Kaniko ,這是一個從 Dockerfile 創建容器映像的實用程序。

Main reason is that Cloudbees goes hand in hand with Kubernetes and the smart people of Google decided that Docker won't do, so they've build this utility, ie Kaniko , that does the same thing as Docker: builds and pushed a Docker image到一個倉庫(你仍然可以使用相同的 Dockerfile)。

暫無
暫無

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

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