【问题标题】:Docker Error in Azure DevOps but not locally?Azure DevOps 中的 Docker 错误,但不在本地?
【发布时间】:2019-07-23 13:23:37
【问题描述】:

我正在尝试运行这个 dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app

COPY . ./
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.0/wait /wait
#RUN chmod +x /wait
RUN /bin/bash -c 'ls -la /wait; chmod +x /wait; ls -la /wait'

CMD /wait && dotnet test --logger trx --results-directory /var/temp /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura && mv /app/tests/Ardalis.Specification.UnitTests/coverage.cobertura.xml /var/temp/coverage.unit.cobertura.xml && mv /app/tests/Ardalis.Specification.IntegrationTests/coverage.cobertura.xml /var/temp/coverage.integration.cobertura.xml

它在我的本地 Windows 机器上运行良好(使用上面第 6-7 行显示的任一 RUN 命令)。

但是当我在 Azure Pipelines 中运行脚本作为构建的一部分时,我得到了这个错误:

我不确定为什么它在 Azure DevOps 中的行为与在我的本地(Windows)机器上的行为不同。构建服务器是 'windows-2019' 映像。它作为 docker-compose 的一部分运行,如果有帮助,请使用此文件:

version: '3.4'

services:
  tests:
    build: 
      context: .
      dockerfile: Dockerfile
    environment:
      WAIT_HOSTS: database:1433
    volumes:
        - ./TestResults:/var/temp

  database:
    image: mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
    environment:
        SA_PASSWORD: "P@ssW0rd!"
        ACCEPT_EULA: "Y"

您可以在此处查看完整的构建跟踪:https://dev.azure.com/Ardalis-Specification/Ardalis.Specification/_build/results?buildId=32

您可以在此处查看 Azure 管道和完整源代码: https://github.com/ardalis/Specification/pull/1

【问题讨论】:

  • 可能构建镜像默认设置为运行windows容器。使用为 Windows 配置的 docker 在本地尝试我的构建脚本......繁荣!同样的错误!
  • 好的,那么如何在我的构建脚本中包含这需要在 Docker for Linux 上运行?
  • 在您的 dockerfile 的同一级别有一个名为wait 的文件,该文件被复制到 imge 中。该文件可能在远程服务器上不存在

标签: azure docker docker-compose azure-devops


【解决方案1】:

显然,Windows 构建代理默认使用 Docker for Windows(Ubuntu 代理使用 Docker for Linux)。没有简单的方法可以在 dockerfile 或 docker-compose 文件中指定容器所需的操作系统(我知道)。我能够通过在本地切换到 Windows 容器来解决路径问题。为了解决 Azure DevOps 上的问题,我将我的 vm 切换到 ubuntu 并修改了我的构建脚本以使用 linux(仍在进行中,但与这个问题无关)。

【讨论】:

  • 是的 - 必须等待 2 天才能让我这样做。如果您愿意,请投票。
【解决方案2】:

在本地 Windows 机器上,您可以运行 Windows 和 Linux 容器。然而不是同时。您可以通过右键单击托盘中的 Docker 图标并从菜单中选择“切换到 Windows/Linux 容器...”来在 Windows 和 Linux 容器之间切换

Switch to Linux containers...

你知道你在本地机器上使用什么类型的容器吗?我假设它是 Linux 容器。切换到 Windows 容器后,您会遇到与 Azure DevOps Pipeline 中相同的错误。 bash 不能在 Windows 上运行(我的意思是没有虚拟化)。

Azure DevOps Windows 构建代理始终运行 Windows 容器。无法运行 Linux 容器,因为它们需要 Windows 上的 Hyper-V,而 Azure 不支持。 您应该在 Ubuntu 构建代理上构建 Linux 容器。

提示:如果要在 Windows 和 Linux 之间共享脚本,请使用 PowerShell Core。这样,相同的构建脚本可以用于 Windows 和 Linux。

【讨论】:

  • 正确,我已经确认如果我在本地使用 Windows 容器,我会重复错误。我不知道我无法在 Azure 构建代理上运行 Linux 容器,因为我可以在本地正常运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-22
  • 2013-04-12
  • 1970-01-01
  • 2019-09-03
  • 2020-05-30
  • 2021-12-28
相关资源
最近更新 更多