azure - 使用 azure 构建管道、自托管代理和 docker-desktop 创建 docker 镜像

标签 azure docker azure-devops azure-container-registry azure-devops-self-hosted-agent

我目前正在使用 azure 构建管道来构建我的 .NET 应用程序,并使用自托管代理和 docker 桌面创建 docker 镜像。创建镜像后,镜像将被推送到 Azure 容器注册表 (ACR)。但是,当我的管道运行时,它无法构建镜像,因为我的自托管代理找不到 docker 守护进程,尽管我的本地 docker-desktop 运行正常。请检查我已完成和想要执行的步骤。

enter image description here

管道:

enter image description here

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Project.API/Project.API.csproj", "Project.API/"]
RUN dotnet restore "Project.API/Project.API.csproj"
COPY . .
WORKDIR "/src/Project.API"
RUN dotnet build "Project.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Project.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.API.dll"]

错误

enter image description here

最佳答案

我尝试在我的环境中重现它并得到以下结果。

注意 - 我怀疑您收到的错误是由于 Azure 代理造成的。可能存在安装不正确的情况。

第 1 步:转至 ADO 组织 > 代理池 > 添加池并创建一个新池。 enter image description here

enter image description here

第 2 步:转到测试池>新代理并按照其中提到的步骤进行操作。 enter image description here

将代理下载到您的计算机并在 power shell 中运行显示的命令。

PS C:\> mkdir agent ; cd agent
PS C:\agent> Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\vsts-agent-win-x64-2.217.2.zip", "$PWD")
PS C:\agent> .\config.cmd

在计算机中配置 azure 代理时,请选择如下所示的选项。

enter image description here

第 3 步:安装并配置 Docker Windows,并使用以下命令验证其是否已启动并正在运行,如下所示。

$docker run hello-world

enter image description here

步骤 4:在 Azure 管道中使用 Dockerfile 构建源代码。 我有一个带有 Dockerfile 的基本 dotnet Web 应用程序,下面是我的 docker 构建管道。 [![在此处输入图像描述][6]][6]

pool: testpool
steps:
  - task: Docker@2
    displayName: Docker build
    inputs:
      command: build
      Dockerfile: devopswebapp/Dockerfile

下面是运行管道后的结果。

enter image description here

关于azure - 使用 azure 构建管道、自托管代理和 docker-desktop 创建 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75590382/

相关文章:

适用于符合 RFC 5988 的 REST API 的 Azure 数据工厂分页 (Meraki)

azure - 删除 Blob 存储中具有名称的所有内容

c# - ASP.NET 视频 webm 未加载

django - "The connection was reset"在本地主机 :8000 using django and docker

iis - 将 asp.net core 配置排除在源代码和管道之外

azure - 找不到部署 ASP.NET Core 7 Web API somepage.azurewebsites.net 页面

c# - 无法加载文件或程序集“Microsoft.Extensions.Logging,版本=7.0.0.0,文化=中性,系统找不到指定的文件”

azure - azure 上的 Windows 服务相当于什么?

symfony - 将带有Filebeat的symfony日志文件传输到本地docker-环境中的graylog

docker - 如何删除现有容器的安装?