skip to Main Content

I am facing problem with installation of .exe file inside docker container:

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN dotnet tool install --global --version 7.3.11 PowerShell 
ADD https://downloads.unidata.ucar.edu/netcdf-c/4.9.2/netCDF4.9.2-NC4-DAP-64.exe lib/netCDF4.9.2-NC4-DAP-64.exe
RUN start-process -Filepath "C:libnetCDF4.9.2-NC4-DAP-64.exe" -Wait -PassThru -ArgumentList "/S" , "/D=C:NetCdf"

CMD ["pwsh"]

After docker build . all steps are running correctly till installation step… Output shows no file to be process:

Step 6/7 : RUN start-process -Filepath "C:libnetCDF4.9.2-NC4-DAP-64.exe" -Wait -PassThru -ArgumentList "/S" , "/D=C:NetCdf"
 ---> Running in 8e200fa39c0f

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00       0.00       0.00    1544

Removing intermediate container 8e200fa39c0f

Checked manually and by "RUN Get-ChildItem -Path "C:libnetCDF4.9.2-NC4-DAP-64.exe" that file is present.

Checked by running…

FROM mcr.microsoft.com/windows:20H2 AS base

ADD https://downloads.unidata.ucar.edu/netcdf-c/4.9.2/netCDF4.9.2-NC4-DAP-64.exe lib/netCDF4.9.2-NC4-DAP-64.exe
RUN powershell Start-Process -filepath 'C:libnetCDF4.9.2-NC4-DAP-64.exe' -Wait -PassThru -ArgumentList '/S' , '/D=C:NetCdf'

…that for old normal PowerShell application is installed correctly:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    168      11     1724       8688       0.09   2292   1 netCDF4.9.2-NC4-DA...

Executing command manually inside container also worked


Is there any related known bug with pwsh tool?
Is there better way to install this file with CMD or even dotnet somehow?
I spent whole day on trying to make it work, so any help would appreciated 🙂

2

Answers


  1. Chosen as BEST ANSWER

    I was not able to install any .exe file with mcr.microsoft.com/dotnet/sdk:7.0 - this one is too limited. Instead I used aspnet:7.0-windowsservercore-ltsc2022 and there powershell scripts worked.


  2. Note:

    • While the information below is true in general, the solution offered turned out not to make a difference, as the command should work even without quoting the strings involved.

    • In principle, you need to -escape " characters in RUN instructions when using PowerShell (either edition) as the shell in a Windows image.

    • Unfortunately, however, this isn’t enough due to a long-standing bug in the .NET tool version of PowerShell (Core), which doesn’t honor even properly escaped " chars. – see GitHub issue #11747

    Therefore, simply use single-quoted ('...' aka verbatim) strings in your command (as you did in the Windows PowerShell call, to powershell.exe):

    RUN Start-Process -Filepath 'C:libnetCDF4.9.2-NC4-DAP-64.exe' -Wait -PassThru -ArgumentList '/S /D=C:NetCdf'
    

    Note:

    • This simple workaround is possible in your case, because your command happens not to require expansions (string interpolation) (which only expandable ("...") string literals in PowerShell provide).

    • Since ' chars. have no syntactic function on the PowerShell CLI’s command line, they can be used without escaping.[1]


    [1] There’s a largely hypothetical caveat: Unless everything that follows -Command is "..."-enclosed overall, the interior of '...' strings that contain spaces are technically passed as multiple arguments, which are then stitched back together with a single space as the separator, before the result is then interpreted as PowerShell code. This results in whitespace normalization: that is, runs of two or more spaces turn into a single space each; e.g., 'foo bar' would become 'foo bar'

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search