如何将Azure管道工件复制到Docker镜像,该镜像是Microsoft dotnetcore运行时映像 [英] How to copy azure pipeline artifacts to a docker image which is microsoft dotnetcore runtime image

查看:94
本文介绍了如何将Azure管道工件复制到Docker镜像,该镜像是Microsoft dotnetcore运行时映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为dotnet核心项目构建一个Azure DevOps管道.在dotnet publish命令执行后,工件被保存在$(artifactStagingDirectory)中.如何将这些工件从登台目录复制到Docker映像?

I'm building an Azure DevOps pipeline for a dotnet core project. After the dotnet publish command executes the artifacts get saved in $(artifactStagingDirectory). How do I copy these artifacts from the staging directory to the docker image?

我不在dockerfile中构建项目.我正在执行管道中的dotnet发布.

I am not building project in dockerfile. I am executing dotnet publish in pipeline.

我试图通过使用以下方式将工件保存到另一个文件夹中:

I have tried to save artifacts to another folder by using:

dotnet publish --configuration $(BuildConfiguration) --output out

推荐答案

发布到$(Build.ArtifactStagingDirectory)很好.有几种方法可以做到,所以这是一种:

Publishing to $(Build.ArtifactStagingDirectory) is fine. There are several ways to do it, so here's one:

  1. 发布后添加一个Docker任务,配置为构建"
  2. 将任务中的构建上下文"设置为$(Build.ArtifactStagingDirectory).这就是Docker将在Dockerfile中用于诸如COPY之类的命令的根路径.
  3. 将Dockerfile提交给您的仓库,并在任务中设置Dockerfile路径以匹配其位置

像这样设置Dockerfile(我在这里假设.NET Core 2.2):

Set up the Dockerfile like this (I'm assuming .NET Core 2.2 here):

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "myAppNameHere.dll"]

由于已将Docker Build Context设置为$(Build.ArtifactStagingDirectory)(已发布应用程序),因此COPY命令会将其用作当前工作目录". COPY的翻译是将$(Build.ArtifactStagingDirectory)中的所有内容复制到容器内的/app文件夹中."

Because you've set the Docker Build Context to $(Build.ArtifactStagingDirectory), where your app has been published, the COPY command will use that as a "current working directory." The translation of the COPY is "copy everything in $(Build.ArtifactStagingDirectory) to the /app folder inside the container."

这将为您提供一个基本的Docker容器,其中仅包含您预先构建和发布的应用程序文件.

That'll get you a basic Docker container that simply contains your pre-built and published app files.

这篇关于如何将Azure管道工件复制到Docker镜像,该镜像是Microsoft dotnetcore运行时映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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