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:
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.
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’.
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:
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>
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.
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,
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.
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 \