Docker Community Forums

Share and learn in the Docker community.

Windows 2019 - Start-Process is not installing application in docker container

I am using Windows Server 2019 with Docker.

I have an application that can be installed in silent mode using start-process in powershell.
Here is the process process:
C:$SILENT=/SILENT
C:\Get-Service to start/stop/status of zyWAF Service
C:\Start-Process .\APP1-8.2.6.windows.x64.exe -ArgumentList “/SILENT /q” -NoNewWindow -Wait

Note: Software got installed and service start without problem.

However, I cannot install the application in a Docker Container.
Here is my docker file:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL [ “powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]
WORKDIR c:/
COPY APP1-8.2.6.windows.x64 ./

ENV VERYSILENT="/VEYSILENT"
CMD [ “powershell.exe” ]
Set-ExecutionPolicy bypass -Force CurrentUser ;
RUN powershell.exe -Command Start-Process “.\APP1-8.2.6.windows.x64.exe” -ArgumentList ‘/VERYSILENT’ -NoNewWindow -RSE ‘juanlog.TXT’ -Wait

Actual behavior

Results:

  • Container got created
  • APP1-8.2.6.windows.x64.exe is copy in the container

But not software installed.

Information

  • Not error in docker or Windows
  • Tried to install manually inside the container running the the same powershell commands. Hit Enter, nothing happen.
    Any help will be appreciated. Thanks.

Docker version:
Client: Mirantis Container Runtime
Version: 20.10.4
API version: 1.41
Go version: go1.13.15
Git commit: 110e091
Built: 04/12/2021 15:53:12
OS/Arch: windows/amd64
Context: default
Experimental: true

Server: Mirantis Container Runtime
Engine:
Version: 20.10.4
API version: 1.41 (minimum version 1.24)
Go version: go1.13.15
Git commit: b24528647a
Built: 04/12/2021 15:51:36
OS/Arch: windows/amd64
Experimental: false

No. I am using Windows Server 2019. My application is named APP1-8.2.6.windows.x64.exe.
It is a 64bit application. That can be install via GUI or powershell command. It has an argument /Silent.

I think you are likely getting bit by the quotation escaping that you are (or are not using) with powershell.exe -Command argument and thus your exe is not running silently like you want it to…probably it is trying to bring up a UI in a container which won’t work. To avoid quotation gotchas you could base64 encode your command and use the -EncodedCommand parameter with PowerShell.exe in your RUN command in your Dockerfile like so:

PS C:\> $command = 'Start-Process .\APP1-8.2.6.windows.x64.exe -ArgumentList "/SILENT /q" -NoNewWindow -Wait'
PS C:\> $bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
PS C:\> $encodedCommand = [Convert]::ToBase64String($bytes)
PS C:\> $encodedCommand
UwB0AGEAcgB0AC0AUAByAG8AYwBlAHMAcwAgAC4AXABBAFAAUAAxAC0AOAAuADIALgA2AC4AdwBpAG4AZABvAHcAcwAuAHgANgA0AC4AZQB4AGUAIAAtAEEAcgBnAHUAbQBlAG4AdABMAGkAcwB0ACAAHCAvAFMASQBMAEUATgBUACAALwBxAB0gIAAtAE4AbwBOAGUAdwBXAGkAbgBkAG8AdwAgAC0AVwBhAGkAdAA=

PS C:\> # In your docker file change your RUN Command to use EncodedCommand
PS C:\># RUN powershell.exe -EncodedCommand UwB0AGEAcgB0AC0AUAByAG8AYwBlAHMAcwAgAC4AXABBAFAAUAAxAC0AOAAuADIALgA2AC4AdwBpAG4AZABvAHcAcwAuAHgANgA0AC4AZQB4AGUAIAAtAEEAcgBnAHUAbQBlAG4AdABMAGkAcwB0ACAAHCAvAFMASQBMAEUATgBUACAALwBxAB0gIAAtAE4AbwBOAGUAdwBXAGkAbgBkAG8AdwAgAC0AVwBhAGkAdAA=

Ryan,
Thanks for the information. I think the problem is exactly what you described.
I still have issues with -EncodedCommand in PS. I am getting:
Start-Process : A parameter cannot be found that matches parameter name ‘EncodedCommand’.

Hey JMunoz,

Not quite sure what you’ve done but it appears ‘-EncodedCommand’ is being passed to the Start-Process cmdlet rather than to the powershell executable (powershell.exe). The -EncodedCommand switch is a powershell.exe argument, not an argument for a cmdlet. Run ‘powershell.exe /?’ and you’ll see all the parameters that powershell.exe accepts. Here’s a quick test you can run (not in a container) just to make sure you have the EncodedCommand part figured out:

PS C:\temp> 'Hello World!' | Set-Content .\hello-world.txt
PS C:\temp> $command = 'Start-Process notepad.exe -ArgumentList ".\hello-world.txt"'
PS C:\temp> $bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
PS C:\temp> $encodedCommand = [Convert]::ToBase64String($bytes)
PS C:\temp> $encodedCommand
UwB0AGEAcgB0AC0AUAByAG8AYwBlAHMAcwAgAG4AbwB0AGUAcABhAGQALgBlAHgAZQAgAC0AQQByAGcAdQBtAGUAbgB0AEwAaQBzAHQAIAAiAC4AXABoAGUAbABsAG8ALQB3AG8AcgBsAGQALgB0AHgAdAAiAA==
PS C:\temp> powershell.exe -encodedCommand $encodedCommand

The excerpt above (open a file in notepad) should just drive home how powershell.exe can accept a base 64 encoded command and run it as you would expect. Once you get that correct for the command you want to do (installing your app) do the same base 64 encoding steps and use that encoded string in your dockerfile:

RUN powershell.exe -EncodedCommand <your-base64-string>

Regards,

Ryan

Hey Ryan,
I really appreciate your help.
Now I understand. Thanks for the clarification.

I did some testing in my windows Server 2019. The process of encoding worked fine. Mean I was able to install the software (Silent), but still doesn’t work when building and run docker container.
I got not error when building the container, but the application doesn’t get installed.

FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL [ “powershell”, “-Command”, “$ErrorActionPreference = ‘Stop’; $ProgressPreference = ‘SilentlyContinue’;”]
WORKDIR c:/
COPY zyWAF-8.2.6-9122.windows.x64.exe ./

ENV VERYSILENT="/VERYSILENT"
CMD [ “powershell.exe” ]
RUN Powershell -encodedCommand

I also check the encode here: Base64 Encode and Decode - Online
I will keep trying.
Thanks,
JMunoz

Hey JMinoz,

Another possibly easier way to skin the cat is to create a batch file that has the correct command line arguments for your install package (verify you got it right outside of a container), then use a copy command in your Dockerfile to copy the batch file in along with your install package and call the batch file for your RUN command (using cmd instead of PowerShell as your shell) rather then trying to do the PowerShell base64 tricks.

Ryan

Ryan,
Yes, I will do this tonight. I already tested the batch file locally. It worked fine.
Just need to add the entry in the dockerfile.
I will let you know the results.
Thanks for all your help.

JMunoz

Hey Ryan,
FYI, I did try copying the installing using the batch file. I got not installation.
I am doing an update of Windows and try again.
I will check if there is another Windows image that I can use to test.
Thanks again.

After so many trials and errors, I was able to install the application using the follow entries:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
COPY WAF-8.2.6.windows.x64.exe ./
RUN powershell.exe -Command
$ErrorActionPreference = ‘Stop’;
Start-Process C:\WAF-8.2.6.windows.x64.exe -ArgumentList ‘/VERYSILENT’ -Wait \

Process:

  • Apply later update to Windows Server 2019
  • Add the path to the file including the drive “C:”
  • Pass one ArgumentList

Thank Ryan for your support.