Reputation: 51
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 says : "As you can see we are in two PSSession one on Nanohost and another into the iambasicone container. Which I think is cool and awesome." For that, he uses :
Enter-PSSession -ContainerName ‘iambasicone’ -RunAsAdministrator
In my case, I want to connect directly from the remote machine to the container. I can't use the same expression because the remote machine doesn't have the Containers feature enabled.
Enter-PSSession : The Containers feature may not be enabled on this machine.
At line:1 char:1
+ Enter-PSSession -ContainerName 10.254.34.70
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Enter-PSSession], PSInvalidOperationException
+ FullyQualifiedErrorId : CreateRemoteRunspaceForContainerFailed,Microsoft.PowerShell.Commands.EnterPSSessionCommand
So, I have to use the -ComputerName option. But then Credentials are needed, and even if I provide them, an access denied is displayed.
Any ideas if what I'm trying to achieve is even possible? Or containers act not like VM's in this situation? (Because I tried to do the same thing with a VM and it works perfectly...)
Upvotes: 3
Views: 1865
Reputation: 605
Not sure how to create an interactive PSSession, but you can access and execute commands on docker containers remotely.
On powershell in local computer enter the following:
$credential = Get-Credential
$remoteComputerName = "10.20.30.40" # your remote machine
$Session = New-PSSession -ComputerName $remoteComputerName -Credential $credential
Invoke-Command -Session $Session -ScriptBlock { docker exec -t my_container_1 redis-cli info replication }
The above, for example, will give redis replication info on your docker container.
Basically use the following pattern:
Invoke-Command -Session $Session -ScriptBlock { docker exec -t <your container> [your commands] }
Upvotes: 0