Powershell remote access to nanoserver on docker Powershell remote access to nanoserver on docker powershell powershell

Powershell remote access to nanoserver on docker


I've been struggling with this for a few days now. However, think my problem is slightly different though, as I'm trying to do an Enter-PSSession to a windows docker container, but from another machine, not the container host.

In this tutorial (http://dinventive.com/blog/2016/01/30/windows-server-core-hello-container/), the guy makes a nested container PSSession inside a host PSSession.

He uses this command, which is only available in the latest versions of Powershell. (not in v3)

Enter-PSSession -ContainerId "<container ID>"

Get the ID by doing :

Get-Container | fl

You also have to check your Powershell version and make an upgrade if needed.

To check PS version :

$PSVersionTable

And to download Powershell latest version : https://www.microsoft.com/en-us/download/details.aspx?id=50395


When connecting to a PS-Session using a IP address it adds some requirements, You must either have the remote device configured to use ssl or have the IP address listed in your trusted hosts.

The solution is to either try use the host name for the device, I have had great success with this. Or play with the trusted hosts list. In my experience it works consistently if you add trusted list entries on your machine and the remote machine as well. You can also specify:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*"

This will basically set all machines to be in the trusted hosts list, It has its cons like all machines being trusted but in certain restricted networks its acceptable. Doing this on the host and client machine seems to yield best results.

When specifying -Credentials it expects a credential object, You can craft one before the cmdlet to avoid entering it every time like so:

$secpass = convertto-securestring "Password Here" -asplaintext -force$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Username Here", $secpass Enter-PSSession -ComputerName "<container ip>" -Credential $cred

Coding credentials like this in a script is bad practice, You should look in to storing credentials in scripts properly, there are plenty of good resources on it.