从远程计算机(不是容器主机)建立到Windows docker容器的PSSession

从远程计算机(不是容器主机)建立到Windows docker容器的PSSession,windows,powershell,docker,containers,remote-access,Windows,Powershell,Docker,Containers,Remote Access,我正在尝试对windows docker容器执行Enter PSSession,但来自另一台计算机,而不是容器主机 在本教程()中,guy在主机PSSession中创建了一个嵌套容器PSSession 他说:“正如你所看到的,我们分为两个阶段,一个是在Nanohost上,另一个是在iambasicone容器中。我认为这很酷也很棒。” 为此,他使用: Enter-PSSession -ContainerName ‘iambasicone’ -RunAsAdministrator 在我的例子中,我

我正在尝试对windows docker容器执行Enter PSSession,但来自另一台计算机,而不是容器主机

在本教程()中,guy在主机PSSession中创建了一个嵌套容器PSSession

他说:“正如你所看到的,我们分为两个阶段,一个是在Nanohost上,另一个是在iambasicone容器中。我认为这很酷也很棒。” 为此,他使用:

Enter-PSSession -ContainerName ‘iambasicone’ -RunAsAdministrator
在我的例子中,我想直接从远程机器连接到容器。我不能使用相同的表达式,因为远程计算机没有启用容器功能

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
因此,我必须使用-ComputerName选项。但是需要凭据,即使我提供了凭据,也会显示拒绝访问


如果我想达到的目标是可能的,有什么想法吗?或者容器在这种情况下不像VM?(因为我试着用虚拟机做同样的事情,它工作得非常完美……

不确定如何创建交互式PSSession,但您可以远程访问和执行docker容器上的命令

在本地计算机的powershell上输入以下内容:

$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 }
例如,上述内容将提供docker容器上的redis复制信息

基本上使用以下模式:

Invoke-Command -Session $Session -ScriptBlock { docker exec -t <your container> [your commands] }
Invoke Command-Session$Session-ScriptBlock{docker exec-t[您的命令]}