Following this description we attempted to create a Windows Docker container that will allow remote (Linux) clients to log in and run Windows PowerShell commands, in our case particularly so that they can use the full set of AzureRM PowerShell CmdLets.
On a Windows Server 2016, build and run the container using the Dockerfile
from this gist. Note that the sshd_config
has an added
subsystem for powershell.
docker build --tag sshserver .
docker run -ti -p 2222:22 sshserver
(you may have to open port 2222 on the host's firewall)
On any other machine, the following now works but is ugly (and certain key-combinations like Ctrl+C don't work):
ssh -p 2222 user@<IP_address_of_win2016_host>
We will end up in a cmd
session, but after entering powershell
we can run our commands. As mentioned though, this is not ideal.
On most OSX clients running PowerShell Core 6.0.0-beta.1 the following works (log in using normal ssh first to ensure ~/.ssh/known_hosts
has been updated properly; there appears to be a bug in the PowerShell SSH client):
powershell
Enter-PSSession -HostName <IP_address_of_win2016_host> -UserName user -SSHTransport -Verbose -Port 2222
This will give a useable system.
Strangely enough, the same never appears to work from a Linux PowerShell Docker container (at the time of this writing, the PowerShell version is identical):
docker run -ti --rm microsoft/powershell
Enter-PSSession -HostName <IP_address_of_win2016_host> -UserName user -SSHTransport -Verbose -Port 2222
Results in:
Enter-PSSession : An error has occurred which Windows PowerShell cannot handle. A remote session might have ended.
At line:1 char:1
+ Enter-PSSession -HostName <IP_address_of_win2016_host> -UserName user -SSHTran ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Enter-PSSession], PSRemotingDataStructureException
+ FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.EnterPSSessionCommand