在Windows容器中运行Visual Studio远程调试器(Docker托管)

Mat*_*adt 16 debugging containers remote-debugging docker windows-server-2016

我尝试在Windows Server 2016 TP4上的Windows容器中运行Visual Studio远程调试器.由于它在容器内运行,因此没有UI.

我尝试通过以下方式运行远程调试器:

 .\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020
Run Code Online (Sandbox Code Playgroud)

我正在以管理员用户(nt authority\system)执行上述操作.这在主机上工作正常,但在容器内部不起作用.Windows事件日志显示以下错误事件.

Msvsmon was unable to start a server named "`6D2D071453C5:4020`". 
The following error occurred: The parameter is incorrect. 
Run Code Online (Sandbox Code Playgroud)

完整的事件日志:

Get-EventLog -LogName Application -EntryType Error | format-list

Index              : 1718
EntryType          : Error
InstanceId         : 3221226473
Message            : The description for Event ID '-1073740823' in Source 'Visual Studio Remote Debugger' cannot be found.  The local computer may not have the necessary registry information or message DLL
                     files to display the message, or you may not have permission to access them.  The following information is part of the event:'Msvsmon was unable to start a server named
                     '6D2D071453C5:4020'. The following error occurred: The parameter is incorrect.

                     View Msvsmon's help for more information.'
Category           : (0)
CategoryNumber     : 0
ReplacementStrings : {Msvsmon was unable to start a server named '6D2D071453C5:4020'. The following error occurred: The parameter is incorrect.

                     View Msvsmon's help for more information.}
Source             : Visual Studio Remote Debugger
TimeGenerated      : 05.04.2016 9:47:19 AM
TimeWritten        : 05.04.2016 9:47:19 AM
UserName           : NT AUTHORITY\SYSTEM
Run Code Online (Sandbox Code Playgroud)

我注意到有关容器主机名的一个问题,但这可以修复:

6D2D071453C5是我的Windows容器的容器ID(docker托管):

PS C:> docker ps -a
CONTAINER ID        IMAGE               COMMAND                   CREATED             STATUS                    PORTS               NAMES
6d2d071453c5        d9d15fbca6d7        "cmd /S /C 'C:\\myprg-"   6 days ago          Up 3 days                                     derrin
Run Code Online (Sandbox Code Playgroud)

通常,在Docker中,此容器ID也将是容器内部/ 的主机名.

所以,当我运行时docker inspect 6d2d071453c5,我在输出中得到这个:

"Config": {
    "Hostname": "6d2d071453c5",
    "Domainname": "",
Run Code Online (Sandbox Code Playgroud)

但是,在容器内部,我hostname在命令行中键入" "并获取:

PS C:> hostname
test2016
Run Code Online (Sandbox Code Playgroud)

这是目前Windows Server 2016 TP4/Windows容器特有的错误.主机名不应该是test2016(容器主机的名称,我的实际物理Win2016服务器),而是容器ID(6d2d071453c5).至少,这将是我预期的行为,当我在需要VM的Windows上运行任何其他容器(即Ubuntu容器)时也是如此.我刚刚重新检查了一下.

然而,为了避免这个问题,我调整了主机文件,添加:

172.16.0.2        6d2d071453c5
Run Code Online (Sandbox Code Playgroud)

现在我至少可以ping我自己的主机名.

PS C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64> ping 6D2D071453C5

Pinging 6d2d071453c5 [172.16.0.2] with 32 bytes of data:
Reply from 172.16.0.2: bytes=32 time<1ms TTL=128
Reply from 172.16.0.2: bytes=32 time<1ms TTL=128
Run Code Online (Sandbox Code Playgroud)

然而,远程调试器仍然无法启动,仍然说:

Msvsmon was unable to start a server named "`6D2D071453C5:4020`". 
The following error occurred: The parameter is incorrect.
Run Code Online (Sandbox Code Playgroud)

根据附带的列出所有参数和选项的帮助文件,我没有看到任何参数有什么问题.同样的命令在容器主机上工作正常,而不是在容器内部.

有没有人让远程调试器在容器内工作?

=======更新======

如下所示,我尝试了hostname参数.我不再在事件日志中看到任何错误,但我也没有看到任何东西正在侦听端口4020.

在目录C:\ Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64中的容器内执行:

> hostname
WIN-DE6U4068NAF

> ".\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020 /hostname WIN-DE6U4068NAF"
.\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020 /hostname WIN-DE6U4068NAF

> netstat -ab | find "4020"

>
Run Code Online (Sandbox Code Playgroud)

小智 1

您是否尝试使用 msvsmon /hostname 选项“硬编码”主机名?

根据 msvsmon 文档: “/hostname hostname_value 指示远程调试器使用指定的主机名值或 IP 地址值侦听网络。在具有多个网卡或具有多个分配的 DNS 主机名的计算机上,可以使用此选项用于限制其中哪些允许远程调试。例如,服务器可能有一个面向互联网的地址和一个内部地址。通过使用“/主机名 private_ip_address”,远程调试将无法通过面向互联网的地址进行。