【问题标题】:Docker Compose build fails in Azure DevOpsAzure DevOps 中的 Docker Compose 构建失败
【发布时间】:2021-02-19 10:04:49
【问题描述】:

在 Azure DevOps 管道中,我正在构建一个包含多个 MVC 和 API 项目的 C# 解决方案。这些项目都支持 Docker (Linux),并且解决方案中还有一个 Docker Compose 项目。 我正在运行 Linux 容器。该解决方案可以在 Visual Studio 2019 中本地构建。 Azure DevOps 中的构建失败并出现以下错误:

DockerComposeProjectBuild:
docker-compose  -f "D:\a\1\s\src\docker-compose.yml" -p dockercompose11375654433676829892 --no-ansi build 
Building my-app
Step 1/15 : FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
5.0-buster-slim: Pulling from dotnet/aspnet
Service 'my-app' failed to build : no matching manifest for windows/amd64 10.0.17763 in the manifest list entries
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(491,5): Error : Your Docker server host is configured for 'Windows', however the docker-compose project targets 'Linux'.

在本地,解决方案构建良好,Docker 容器也运行良好。 我的构建管道配置为使用 Windows:

pool:
  vmImage: 'windows-latest'

当我切换到 ubuntu-latest 时,构建步骤立即失败:

2021-02-19T09:21:06.4937649Z ##[section]Starting: Build
2021-02-19T09:21:06.4946601Z ==============================================================================
2021-02-19T09:21:06.4947180Z Task         : Visual Studio build
2021-02-19T09:21:06.4947617Z Description  : Build with MSBuild and set the Visual Studio version property
2021-02-19T09:21:06.4949185Z Version      : 1.166.2
2021-02-19T09:21:06.4949536Z Author       : Microsoft Corporation
2021-02-19T09:21:06.4950010Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
2021-02-19T09:21:06.4950534Z ==============================================================================
2021-02-19T09:21:06.5069612Z ##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
2021-02-19T09:21:06.5083222Z ##[section]Finishing: Build

我曾尝试在解决方案属性中禁用 Docker Compose 项目的构建,但这似乎没有任何影响。

如何更改管道以解决此问题? 如果在构建过程中通过管道跳过 Docker Compose 项目也可以。

【问题讨论】:

  • 您的问题进展如何?

标签: visual-studio docker-compose azure-devops .net-5


【解决方案1】:

您在 Azure Pipelines 中使用 Windows 构建机器:

pool:
  vmImage: 'windows-latest'

您要求 Windows 机器构建 Linux 容器:

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim

此容器映像无法在 Windows 上运行,如错误所示:

no matching manifest for windows/amd64

您想使用 Linux 容器,所以只需 use a different pool

pool:
  vmImage: 'ubuntu-latest'

【讨论】:

  • Doc 对此非常明确:“可以使用 Microsoft 托管的 Windows 代理或基于 Windows 平台的自托管代理来构建 Windows 容器映像(所有 Microsoft 托管的基于 Windows 平台的代理都与 Moby 一起提供) Docker 构建所需的引擎和客户端)。可以使用 Microsoft 托管的 Ubuntu-16.04 代理或基于 Linux 平台的自托管代理来构建 Linux 容器映像。”
【解决方案2】:

尝试从 Visual Studio 中卸载 docker 项目并编辑项目并将值“Windows”设置为“DockerTargetOS”。

<DockerTargetOS>Windows</DockerTargetOS>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 2020-06-15
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 2020-11-25
    相关资源
    最近更新 更多