[英]Connect to docker container on windows host from another machine
[英]Establish PSSession to Windows docker container from remote machine (not container host)
我正在嘗試對Windows Docker容器執行Enter-PSSession,但是從另一台機器而不是容器主機執行。
在本教程( http://dinventive.com/blog/2016/01/30/windows-server-core-hello-container/ )中,該人在主機PSSession中創建了一個嵌套容器PSSession。
他說:“正如你所看到的,我們在Nanohost上有兩個PSSession,另一個在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選項。 但是需要Credentials,即使我提供了憑據,也會顯示拒絕訪問權限。
如果我想要實現的任何想法甚至可能嗎? 或者容器在這種情況下不像VM一樣? (因為我試圖用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] }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.