在Windows容器中运行Visual Studio远程debugging器(托pipe的Docker)

我尝试在Windows Server 2016 TP4Windows容器中运行Visual Studio远程debugging器 。 由于它在容器中运行,因此不存在用户界面。

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

.\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020 

我正在以pipe理员用户(NT权限\系统)执行上述操作。 这在主机上工作正常,但在容器内不起作用。 Windows事件日志显示以下错误事件。

 Msvsmon was unable to start a server named "`6D2D071453C5:4020`". The following error occurred: The parameter is incorrect. 

完整的事件日志:

 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 

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

6D2D071453C5是我的Windows容器( 6D2D071453C5 )的容器ID

 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 

通常,在Docker中,这个容器ID也将是容器内部的主机名

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

 "Config": { "Hostname": "6d2d071453c5", "Domainname": "", 

但是,在容器内部,我在命令行中键入“ hostname ”,并得到:

 PS C:> hostname test2016 

这是Windows Server 2016 TP4 / Windows Containers特定的错误。 主机名不应该是test2016 (容器主机的名称,我的实际物理Win2016服务器),而是容器标识( 6d2d071453c5 )。 至less,这将是我的预期行为,当我在Windows上运行任何其他容器(即Ubuntu容器)时,也需要虚拟机。 我只是重新检查它。

尽pipe如此,为了避免这个问题,我调整了主机文件,增加:

 172.16.0.2 6d2d071453c5 

现在我至less可以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 

尽pipe如此,远程debugging器仍然不启动,仍然说:

 Msvsmon was unable to start a server named "`6D2D071453C5:4020`". The following error occurred: The parameter is incorrect. 

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

有没有人得到远程debugging器在一个容器内工作?

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

如下所示,我尝试了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" > 

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

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

好的,在这里抛出真正的明显。 从你的post,命令

“。\ msvsmon.exe / nostatus / silent / nosecuritywarn / nofirewallwarn / noclrwarn / port 4020 / hostname WIN-DE6U4068NAF”

只会在PowerShell中打印完全相同的string。 它实际上并不启动debugging器。 回声输出显示了这一点。 (我可能读得太多了)

所以/nofirewallwarn只能抑制被防火墙警告(YMMV)阻止,并不实际通过防火墙。 你用/prepcomputer先运行它吗?

你有没有尝试过/anyuser绕过authentication,只允许TCP工作?

msvsmon实际上绑定到正确的networking接口? 有时绑定到回送适配器意味着它只能在本地访问。 当你netstat它显示监听所有接口( 0.0.0.0 )?

你有没有尝试使用/service选项作为服务运行它? 不过,可能还有一些陷阱。 我通常很难在现场工作。

要进行debugging,您需要将远程工具安装到映像中,按照常规运行容器,然后使用docker exec启动远程debugging器。

命令行如下:

docker exec -it <container id/name> "C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe" /nostatus /silent /noauth /anyuser /nosecuritywarn

我在博客文章中有更多的细节,是的,closures本地开发机器上的authentication确实会带来一些风险(无论多小),但至less应该给你一个如何去做的想法。 你总是可以调整命令行选项,让它按照你想要的方式工作。

我发现这个序列的工作:

 PS C:\> start-service msvsmon150 PS C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64> .\msvsmon /noauth /anyuser /silent 

start-Service命令将放弃有关在Windows 10托pipe的Windows容器中运行时服务无法启动的错误。 但是,input第二个命令后,端口在netstat -ab中显示为被阻止,Visual Studio 2017可以嗅探debugging器单元。