【问题标题】:Establish PSSession to Windows docker container from remote machine (not container host)从远程机器(不是容器主机)建立到 Windows docker 容器的 PSSession
【发布时间】:2017-05-20 07:11:35
【问题描述】:

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

在本教程 (http://dinventive.com/blog/2016/01/30/windows-server-core-hello-container/) 中,这个家伙在主机 PSSession 中创建了一个嵌套容器 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 选项。但是随后需要凭据,即使我提供了凭据,也会显示拒绝访问。

如果我想要实现的目标是可能的,有什么想法吗?或者容器在这种情况下的行为不像虚拟机? (因为我尝试用虚拟机做同样的事情,而且效果很好......)

【问题讨论】:

    标签: windows powershell docker containers remote-access


    【解决方案1】:

    不确定如何创建交互式 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] }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2016-03-19
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多