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

Debugging 在Windows容器中运行Visual Studio远程调试器(Docker管理),debugging,docker,containers,remote-debugging,windows-server-2016,Debugging,Docker,Containers,Remote Debugging,Windows Server 2016,我尝试在Windows Server 2016 TP4上的Windows容器中运行Visual Studio远程调试器。因为它在容器中运行,所以没有UI 我尝试通过以下方式运行远程调试器: .\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020 我以管理员用户(nt authority\system)的身份执行上述操作。 这在主机上可以正常工作,但在容器中不起作用。Window

我尝试在Windows Server 2016 TP4上的Windows容器中运行Visual Studio远程调试器。因为它在容器中运行,所以没有UI

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

 .\msvsmon.exe /nostatus /silent /nosecuritywarn /nofirewallwarn /noclrwarn /port 4020
我以管理员用户(nt authority\system)的身份执行上述操作。 这在主机上可以正常工作,但在容器中不起作用。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容器(docker管理)的容器id

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

因此,当我运行
docker inspect 6d2d071453c5
时,我在输出中得到以下信息:

"Config": {
    "Hostname": "6d2d071453c5",
    "Domainname": "",
但是,在容器内部,我在命令行中键入“
hostname
”,并获得:

PS C:> hostname
test2016
这是目前Windows Server 2016 TP4/Windows容器特有的一个bug。 主机名不应该是
test2016
(容器主机的名称,我的实际物理Win2016服务器),而应该是容器id(
6d2d071453c5
)。 至少,这是我预期的行为,当我在需要虚拟机的Windows上运行任何其他容器(如Ubuntu容器)时也是如此。我只是重新检查了一下

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

172.16.0.2        6d2d071453c5
现在我至少可以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
根据附带的帮助文件列出的所有参数和选项,我看不出任何参数有什么问题。同样的命令在容器主机上运行良好,只是不在容器内部

有人让远程调试器在容器中工作吗

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

正如下面所建议的,我尝试了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\u value指示远程调试器使用指定的主机名值或IP地址值在网络上侦听。在具有多个网卡或分配了多个DNS主机名的计算机上,此选项可用于限制其中哪些允许远程调试。例如,服务器可能具有internet fa。”ip地址和内部地址。通过使用“/hostname private\u ip\u address”,将无法通过面向internet的地址进行远程调试。”

好的,在这里抛出真正明显的问题。 在你的岗位上,指挥部

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

将在powershell中打印完全相同的字符串。它实际上并没有启动调试器。回波输出显示了这一点。(我可能读得太多了)

因此,
/nofirewallwarn
只会抑制被防火墙阻止的警告(YMMV),实际上不会通过防火墙。您是否先用
/prepcomputer
运行它

您是否尝试过
/anyuser
绕过身份验证,只允许TCP工作

msvsmon是否实际绑定到正确的网络接口?有时,绑定到环回适配器意味着它只能在本地访问。当您
netstat
时,它是否显示监听所有接口(
0.0.0

您是否尝试过使用
/service
选项将其作为服务运行?
不过,可能还有更多的陷阱。我通常很难让它在现场工作。

要进行调试,您需要将远程工具安装到映像中,按照正常方式运行容器,然后使用
docker exec
启动远程调试器

命令行如下所示:

docker exec-it“C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe”/nostatus/silent/noauth/anyuser/nosecuritywarn


我已经有了更多的细节,是的,在您本地的开发机器上关闭auth确实会带来一些风险(无论风险有多小),但这至少应该让您知道如何做。您可以随时调整命令行选项,使其以您想要的方式工作。

我发现这个序列可以工作:

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

“启动服务”命令将显示一个错误,说明在Windows 10托管的Windows容器中运行时服务如何无法启动。但是,在输入第二个命令后,端口在netstat-ab中显示为阻塞,Visual Studio 2017可以嗅探调试器单元。

添加了关于主机名的docker问题:主机名问题似乎是Server 2016 TP4中已知的Windows容器问题,请参阅。然而,我原来的问题仍然存在。主机名问题在服务器2016 TP5中得到了解决,但是,仍然没有让远程调试器对其进行处理。我知道这是一篇老文章,但我看到docker ps-a中没有端口。。。我想你的调试器找不到带有端口的docker容器,因为你没有在Dockerfile中设置EXPOSE 4020。谢谢你的回答。我已经没有这个环境了,所以我现在不能再测试它了。与此同时,这个项目已经过时了。我想我也没有使用冒号
运行它,但不确定,因为这就是我在主机上运行它来测试它的方式(参见我的第一个命令行)。您是否让调试器在您这边的容器内运行?因为您提到“我通常很难让它在现场工作。”我已经尝试过了
> 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"

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