Saturday 17 December 2022

Resolve "encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)"

 As discussed in the post "Run .NET Core 3.1 Application with Windows Server Core 2019 Docker Image" there could be situations you need to setup .NET Core 3.1 on Windows servercore docker image. However, you might have experienced below error running Windows container, when you setup tools such as .NET runtime by yourself using dockerfile. 


Let's see one such example case and how it can be fixed with .NET Core runtime 3.1 installed on Windows servercore docker image.

Intially when the below code is used with mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019 image the .NET Core 3.1 could run without any issues with docker run.

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019 AS base

# install .NET Core 3.1 runtime
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ADD https://dot.net/v1/dotnet-install.ps1 C:/setup/dotnet-install.ps1
RUN C:/setup/dotnet-install.ps1 -Runtime aspnetcore -Channel 3.1 -Version latest -InstallDir '/Program Files/dotnet'
ENV DOTNET_ROOT="c:\Program Files\dotnet"

But with mcr.microsoft.com/windows/servercore:ltsc2019 image the app ran into the issue below.

docker: Error response from daemon: container 2988fbxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc 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!00007FF795819FAB: (caller: 00007FF7957CE19A) Exception(4) tid(394) 80070002 The system cannot find the file specified.

    CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess]

 Provider: 00000000-0000-0000-0000-000000000000].

Looking at the docker build log shows with the mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019 image the installation of the .NET Core runtime is not having any problem while the mcr.microsoft.com/windows/servercore:ltsc2019 showing an issue of not adding the dotnet path to environment path to be used by all processes.

Build log

mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019


mcr.microsoft.com/windows/servercore:ltsc2019



Fix

To fix adding below line setting the .NET path to PATH, after installation of .NET Core 3.1 runtime is required.

# Add .NET Core to path
RUN setx /M PATH $(${Env:PATH} + ';C:\Program Files\dotnet')

The steps in full are as below


The log then shows the path is correctly saved and the error "encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)" does not happen in docker run.







No comments:

Popular Posts