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

标签 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)执行上述操作。 这在主机上工作正常,但在容器内不起作用。 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 管理)的 container 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 中,这个 container id 也将是容器内部/的 hostname

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

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

然后,在容器内,我在命令行中输入“hostname”并得到:

PS C:> hostname
test2016

这是目前特定于 Windows Server 2016 TP4/Windows 容器的错误。 主机名不应是 test2016(容器主机的名称,我的实际物理 Win2016 服务器),而是容器 id (6d2d071453c5)。 至少,这将是我的预期行为,当我在需要 VM 的 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

尽管如此,远程调试器仍然没有启动,并且仍然说:

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

根据列出所有参数和选项的随附帮助文件,我看不出任何参数有什么问题。相同的命令在容器主机上运行良好,只是不在容器内。

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

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

如下所示,我尝试了主机名参数。我不再在事件日志中看到任何错误,但我也没有看到任何东西正在监听端口 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"

>

最佳答案

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

命令行如下:

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

我在 a blog post 中有更多详细信息,是的,在您的本地开发机器上关闭身份验证确实会带来一些风险(无论多么小),但这至少应该让您知道如何去做。你可以随时调整命令行选项,让它按照你想要的方式工作。

关于debugging - 在 Windows 容器中运行 Visual Studio 远程调试器(由 Docker 管理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420337/

相关文章:

bash - Fedora 容器 No 'find' 命令可用

c# - Visual Studio 2015 中没有生成 pdb

c - 在 C 中是否有调用堆栈转储的函数?

Java 11 : Strange behaviour with Object. equals() 方法

debugging - Elisp:符号作为变量的值在 let* 和 (lambda) 中是无效的

java - 在 Docker 上运行时,Spring Boot 上传功能在生产环境中不起作用

docker - 损坏的 DAG : (. ..) 没有名为 docker 的模块

docker - docker 可以有多个日志记录驱动程序吗?

docker - 为什么即使安装并准备就绪,我也无法像其他可执行文件一样执行minikube?

STL - c++0x 中的不可变设置键在哪里?