如何解决‘容器操作系统与主机操作系统不匹配’错误?
解决Azure Cosmos DB模拟器容器启动时的OS不匹配错误
问题描述
我在构建流水线中配置Azure Cosmos DB模拟器以运行数据层单元测试,使用的任务配置如下:
- task: azure-cosmosdb.emulator-public-preview.run-cosmosdbemulatorcontainer.CosmosDbEmulator@2 displayName: 'Run Azure Cosmos DB Emulator container' enabled: true
流水线运行时镜像下载成功,但启动容器时抛出错误:
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
主机为Windows系统,项目无Dockerfile,流水线未配置独立Docker任务,Docker版本24.0.7。
解决方案
1. 指定匹配主机版本的容器镜像
Azure Cosmos DB Windows模拟器容器要求主机Windows版本与镜像版本严格匹配。默认的latest标签可能指向与当前主机不兼容的旧版本镜像,需手动指定对应版本:
- 若主机是Windows Server 2022,使用
2022-latest标签 - 若主机是Windows Server 2019,使用
2019-latest标签
修改任务配置:
- task: azure-cosmosdb.emulator-public-preview.run-cosmosdbemulatorcontainer.CosmosDbEmulator@2 displayName: 'Run Azure Cosmos DB Emulator container' enabled: true inputs: image: 'mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator:2022-latest'
2. 确保Docker处于Windows容器模式
Windows Docker支持Windows/Linux两种容器模式,当前使用的是Windows版本镜像,需确认Docker处于Windows容器模式:
- 自托管代理:右键任务栏Docker图标,选择「切换到Windows容器」
- 微软托管代理:选择
windows-2022或windows-2019代理池,这类代理默认配置为Windows容器模式
3. 启用主机的Windows容器功能
自托管代理主机需确保已启用容器相关Windows功能:
- 以管理员权限打开PowerShell
- 运行命令:
Enable-WindowsOptionalFeature -Online -FeatureName containers -All
- 重启主机后重新运行流水线
4. 调整Docker运行模式
若启用了WSL 2引擎,可能存在版本不兼容问题:
- 打开Docker设置,暂时关闭「使用WSL 2引擎」选项,切换为Hyper-V模式运行Windows容器
- 或升级WSL到最新版本,确保WSL的Windows内核与主机版本匹配
内容的提问来源于stack exchange,提问作者Juned Mulla
相关产品推荐
相关产品推荐

