"The system cannot find the file specified." 当 运行 ECS Fargate 任务时

"The system cannot find the file specified." when running ECS Fargate task

我正在尝试 运行 AWS ECS 上的 Fargate (Windows) 任务,但它一结束就失败,处于“待处理”状态。我不确定我错过了什么。只有 1 个可能的文件会导致此问题 - Wait-Service.ps1 但我不明白为什么不应该找到它。

Wait-Service.ps1 文件位于 bin/Debug 文件夹中。

这是我的 Dockerfile:

# escape=\

FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN "mkdir C:\temp"

WORKDIR "C:/service"

COPY bin/Debug/ .

RUN "C:/Windows/Microsoft.NET/Framework64/v4.0.30319/installutil.exe" /LogToConsole=true /ShowCallStack ./SprProductionDataService.exe; \
  Set-Service -Name "\"SprProductionDataService\"" -StartupType Automatic; 

#The container stays up as long as this process is running.
CMD "C:/service/Wait-Service.ps1" -ServiceName "SprProductionDataService" -StartupTimeout 10 -AllowServiceRestart;

我只看到这条错误消息(在 AWS 控制台中):

Status reason   CannotStartContainerError: CannotStartContainerError: 
hcs::System::CreateProcess 5d85964e54844ae0ad18140057019deb-4109322994: 
The system cannot find the file specified.: unknown

更新:

我尝试 运行 容器从 ECR 存储库中提取它,但它也失败了:

PS D:\_Code\SPRProductionDataService\SprProductionDataService> docker run --name sprprod -it spr-production-service-dev-ecr:latest 208555724522.dkr.ecr.us-west-2.amazonaws.com/spr-production-service-dev-ecr:latest powershell
docker: Error response from daemon: container e1658203aca736881659e1a5445e8d0ec549ccf94fe2f2952012752e330d9826 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF7FACA9F4B: (caller: 00007FF7FAC5E13A) Exception(2) tid(3a4) 80070002 The system cannot find the file specified.
    CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]
 Provider: 00000000-0000-0000-0000-000000000000].

进一步挖掘后,我发现我没有指定容器的 ENTRYPOINT,在我的例子中是 powershell。波纹管 dockerfile 对我有用:

# escape=\

FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN "mkdir C:\temp"

WORKDIR "C:/service"

COPY bin/Debug/ .

# For debugging purposes only
#RUN Enable-WindowsOptionalFeature -Online -FeatureName "TelnetClient"

RUN "C:/Windows/Microsoft.NET/Framework64/v4.0.30319/installutil.exe" /LogToConsole=true /ShowCallStack ./SprProductionDataService.exe; \
  Set-Service -Name "SprProductionDataService" -StartupType Automatic; 

#The container stays up as long as this process is running.
ENTRYPOINT ["powershell.exe"]
CMD ["C:/service/Wait-Service.ps1", "-ServiceName", "SprProductionDataService", "-StartupTimeout", "10", "-AllowServiceRestart"];

这里的问题是 ENTRYPOINT/CMD 的指定方式。

在第一个 Dockerfile 中,您以 shell 形式指定了 CMD。 在第二个 Dockerfile 中,您以 exec 形式指定了 ENTRYPOINT 和 CMD。参考 - This

基本上,ECS Fargate 运行 containerd 运行时,这个运行时在处理 shell 表单时效果不佳。

有一个开放的 github issue 描述了行为。