如何将 azure 管道工件复制到作为 microsoft dotnetcore 运行时映像的 docker 映像 [英] How to copy azure pipeline artifacts to a docker image which is microsoft dotnetcore runtime image

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

问题描述

我正在为 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 publish.

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 任务,配置为Build"
  2. 将任务中的构建上下文"设置为 $(Build.ArtifactStagingDirectory).这是 Docker 将用于 Dockerfile 中的 COPY 等命令的根路径.
  3. 将 Dockerfile 提交到您的 repo,并在任务中设置 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.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 管道工件复制到作为 microsoft dotnetcore 运行时映像的 docker 映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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