How to fix "The container operating system does not match the host operating system" error

182 Views Asked by At

I have been trying to run my data-layer unit test case through pipeline. For database I am using cosmosdb. For runing these test we need cosmosdb emulator which have configured in build pipeline.

- task: azure-cosmosdb.emulator-public-preview.run-cosmosdbemulatorcontainer.CosmosDbEmulator@2
  displayName: 'Run Azure Cosmos DB Emulator container'
  enabled: true

Here it creates image of container which get created successfully while running pipeline but soon after this it throws error-->

Status: Downloaded newer image for mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator:latest
 container 65d00cecdf71adbb12accb38f89a9980681ab32b215a1b67e4973d01fc4e912b created from image mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator:latest
docker start 65d00cecdf71adbb12accb38f89a9980681ab32b215a1b67e4973d01fc4e912b
Error response from daemon: hcs::CreateComputeSystem 65d00cecdf71adbb12accb38f89a9980681ab32b215a1b67e4973d01fc4e912b: The container operating system does not match the host operating system.
Error: failed to start containers: 65d00cecdf71adbb12accb38f89a9980681ab32b215a1b67e4973d01fc4e912b

Task failed: container 65d00cecdf71adbb12accb38f89a9980681ab32b215a1b67e4973d01fc4e912b failed to start

My host machine is running on Windows and for docker, I do not have dockerfile in my project also docker task in my build pipeline since it all has configured in above task itself. I checked docker version and it is 24.0.7.

How should I resolve this issue?

1

There are 1 best solutions below

0
Kevin Lu-MSFT On

I can reproduce the same issue in Azure DevOps.

enter image description here

Refer to this doc: Set up a CI/CD pipeline with the Azure Cosmos DB Emulator build task in Azure DevOps

Due to the full removal of Windows 2016 hosted runners on April 1st, 2022, this method of using the Azure Cosmos DB emulator with build task in Azure DevOps is no longer supported.

Currently, we are not able to use the Azure Cosmos DB Emulator task in Azure DevOps now.

To solve this issue, we can use the PowerShell script to start the emulator.

For Microsoft-Hosted agent windows-2019:

# Write your PowerShell commands here.

dir "C:\Program Files\Azure Cosmos DB Emulator\"

Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"

$startEmulatorCmd = "Start-CosmosDbEmulator -NoFirewall -NoUI"
Write-Host $startEmulatorCmd
Invoke-Expression -Command $startEmulatorCmd

# Pipe an emulator info object to the output stream

$Emulator = Get-Item "$env:ProgramFiles\Azure Cosmos DB Emulator\Microsoft.Azure.Cosmos.Emulator.exe"
$IPAddress = Get-NetIPAddress -AddressFamily IPV4 -AddressState Preferred -PrefixOrigin Manual | Select-Object IPAddress

New-Object PSObject @{
Emulator = $Emulator.BaseName
Version = $Emulator.VersionInfo.ProductVersion
Endpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "https://${_}:8081/" }
MongoDBEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "mongodb://${_}:10255/" }
CassandraEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "tcp://${_}:10350/" }
GremlinEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "http://${_}:8901/" }
TableEndpoint = @($(hostname), $IPAddress.IPAddress) | ForEach-Object { "https://${_}:8902/" }
IPAddress = $IPAddress.IPAddress
}

For self-hosted agent, we need to download and install the latest emulator's MSI package from https://aka.ms/cosmosdb-emulator. Then we can run the Powershell script to start the emulator.