1

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:\lib\netCDF4.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:\lib\netCDF4.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:\lib\netCDF4.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:\lib\netCDF4.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 2

1

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:\lib\netCDF4.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'

7
  • Unfortunately single quote does not work either
    – Julia
    Commented Feb 2, 2024 at 21:25
  • Good point, @Julia: I now see that your command would work even without any quoting at all, given that the strings do not contain spaces and contain no PowerShell metacharacters.
    – mklement0
    Commented Feb 2, 2024 at 21:49
  • @Julia: It's clearly starting some process. Could it be that this simply a display problem, and that the installer ran properly just the same, or have you verified that it doesn't run?
    – mklement0
    Commented Feb 2, 2024 at 21:51
  • @Julia: It looks like a version of pwsh is preinstalled in the image, otherwise it wouldn't be able to run the RUN dotnet tool ... instruction that installs pwsh as a global tool, right? Which version is that?
    – mklement0
    Commented Feb 2, 2024 at 21:55
  • 1
    I checked that netCDF4.9.2-NC4-DAP-64.exe is created in container, but the location for files that should be installed is not even created. It seems like the installation is missing something in container from mcr.microsoft.com/dotnet/sdk:7.0 image, but I can't took out logs from it. I tried "-RedirectStandardOutput stdout.txt -RedirectStandardError stderr.txt" commands, but files turned out to be empty. Also I tried the same scenario with 7zip installer and the result was the same. For mcr.microsoft.com/windows:20H2 image everything works smooth for both - netcdf and 7zip .exes.
    – Julia
    Commented Feb 2, 2024 at 22:42
0

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.