如何替换Dockerfile中的--from标记以能够在Jenkins管道中构建映像 [英] How to replace --from tag in Dockerfile to be able to build the image from within Jenkins pipeline

查看:628
本文介绍了如何替换Dockerfile中的--from标记以能够在Jenkins管道中构建映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Dockerfile:

FROM docker.m.our-intra.net/microsoft/dotnet:2.1-sdk
WORKDIR /app
COPY . ./aspnetapp/
WORKDIR /app/aspnetapp
RUN dotnet publish -c Release -o out

FROM docker.m.our-intra.net/microsoft/dotnet:2.1.4-aspnetcore-runtime
WORKDIR /app
COPY --from=docker.m.our-intra.net/microsoft/dotnet:2.1-sdk /app/aspnetapp/MyProject.WebApi/out ./
ENTRYPOINT ["dotnet", "MyProject.WebApi.dll"]

该图像已在本地成功构建.

The image is builded locally successfully.

我正在尝试配置Jenkins管道,并尝试使用以下步骤从Jenkinsfile构建映像:

I'm trying to configure a Jenkins pipeline and try to build the image from Jenkinsfile using the following step:

stage('Build') {
            steps {
                script {
                    echo 'Build...'
                    sh 'docker build -t mytag:v${BUILD_NUMBER} -f Dockerfile .'
                    echo 'Build Completed'
                }               
            }
        }

但是在Jenkins控制台中,我得到了错误:

But In Jenkins console I get the error:

未知标志:来自

我应该如何编辑我的Dockerfile标记,尤其是--from标记,以便能够在本地以及通过Jenkins管道构建图像?

How should I edit my Dockerfile, particularly --from tag in order to able to build the image locally and through Jenkins pipeline?

更新: 我已经将Docker更新为18.06.1-ce版本.仍然有相同的错误.

UPDATE: I've updated the Docker to 18.06.1-ce version. Still have the same error.

詹金斯版2.89.4

Jenkins ver. 2.89.4

Docker Pipeline插件安装版本1.9.1

Docker Pipeline plugin installed version 1.9.1

更新2: 我添加了docker version命令向我展示Docker版本:

UPDATE 2: I added the docker version command to show me the Docker version:

stage('Build') {
            steps {
                script {
                    echo 'Build...'
                    sh 'docker version'
                    sh 'docker build -t fact:v${BUILD_NUMBER} -f Dockerfile .'
                    echo 'Build Completed'
                }               
            }
        }

它会输出以下内容:

Client:
 Version:           18.06.1-ce
 API version:       1.24 (downgraded from 1.38)
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:25:03 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          1.12.6
  API version:      1.24 (minimum version )
  Go version:       go1.8.3
  Git commit:       3e8e77d/1.12.6
  Built:            Wed Dec 13 12:18:58 2017
  OS/Arch:          linux/amd64
  Experimental:     false

推荐答案

我认为这是docker引擎版本问题.您的Jenkins机器上的Docker引擎版本必须为17.05或更高版本,才能支持--from或多阶段构建.

I believe it's a docker engine version issue. Docker engine version needs to be 17.05 or later on your Jenkins machine to support --from or multi-stage builds.

来自文档-

多阶段构建是一项新功能,需要Docker 17.05或更高版本 在守护程序和客户端上.

Multi-stage builds are a new feature requiring Docker 17.05 or higher on the daemon and client.

参考- https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds

这篇关于如何替换Dockerfile中的--from标记以能够在Jenkins管道中构建映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆