Reputation: 8962
I'm trying to run this 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
It works fine on my local Windows machine (with either of the RUN commands shown on line 6-7 above).
But when I run the script as part of a build in Azure Pipelines I get this error:
I'm not sure why it's behaving differently in Azure DevOps than on my local (windows) machine. The build server is the 'windows-2019' image. It's being run as part of docker-compose, with this file, if it helps:
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"
You can see the full build trace here: https://dev.azure.com/Ardalis-Specification/Ardalis.Specification/_build/results?buildId=32
You can view the azure pipeline and full source here: https://github.com/ardalis/Specification/pull/1
Upvotes: 2
Views: 2742
Reputation: 21
On local Windows machine you can run both Windows and Linux containers. However not at the same time. You can switch between Windows and Linux containers by right-clicking on Docker icon in tray and selecting from menu "Switch to Windows/Linux containers..."
Do you know what type of containers are you using on local machine? I assume it's Linux containers. And after switching to Windows containers, you would get the same error as in Azure DevOps Pipeline. bash does not run on Windows (I mean not without virtualization).
Azure DevOps Windows build agents always run Windows containers. It's not possible to run Linux containers, because they need Hyper-V on Windows and this is not supported by Azure. You should build Linux containers on Ubuntu build agent.
Tip: If you want to share scripts between Windows and Linux, use PowerShell Core. That way same build script can be used for Windows and Linux.
Upvotes: 2
Reputation: 8962
Apparently windows build agents use Docker for Windows by default (and Ubuntu agents use Docker for Linux). There's no easy way to specify in a dockerfile or docker-compose file which OS you require for a container (that I know of). I was able to repo the path issue by switching to Windows containers locally. To address the problem on Azure DevOps I switched my vm to ubuntu and modified my build script to work with linux (still in progress, but not related to this question).
Upvotes: 3