微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Windows 10 容器上启用远程桌面

如何解决在 Windows 10 容器上启用远程桌面

我正在尝试在容器映像上启用远程桌面。

Dockerfile

FROM mcr.microsoft.com/windows:2004

EXPOSE 3389

RUN net user administrator Stack0verflow
RUN net user administrator /active:yes

# I tried disabling the firewall; but this command errors as Windows Defender Firewall service 
# is not enabled; so presumably if the firewall's not running,it's not a firewall issue.
#RUN netsh advfirewall set allprofiles state off

# switch shell to powershell (note: pwsh not available on the image)
SHELL ["powershell","-Command","$ErrorActionPreference = 'Stop'; $Progresspreference = 'SilentlyContinue'; $ExecutionPolicy = 'Unrestricted';"]

# enable RDP (value is 1 on the base image)
RUN Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'fDenyTSConnections' -Type 'DWord' -Value 0
# per https://www.withinrafael.com/2018/03/09/using-remote-desktop-services-in-containers/
RUN Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'TemporaryALiC' -Type 'DWord' -Value 1

注意:由于它是 Windows 映像,我已将 Docker 桌面切换到 Windows 容器(参考:Docker: "no matching manifest for windows/amd64 in the manifest list entries"

然后我通过以下方式构建此映像:docker build -t win10poc .

...并通过以下方式运行它:docker run --expose 3389 --publish 3390:3389 -it win10poc

容器运行成功;但我无法连接到它(在主机设备上使用计算机名称mstsc127.0.0.1:3390;甚至执行 Test-NetConnection -ComputerName 127.0.0.1 -Port 3390)。

我也试过从容器的命令提示符运行 powershell -command "Test-NetConnection -ComputerName 'localhost' -Port 3389";但这也会返回失败;提示该服务未在此端口上侦听。

注意:在容器上运行 net start TermService 返回 The requested service has already been started;所以它应该在倾听。

我的主机设备运行的是 Windows 10.0.19041.264。

注意:我看到了一个类似的问题 Windows Server;尽管再次询问,因为那是针对服务器而不是桌面,但该问题关于尝试过的内容的信息较少,并且没有答案。因此,我希望这不会被视为重复。

解决方法

用于构建 Dockerfile 的 reference you used 声明在 1709_KB4074588 之后 RDP 无法再工作。今天拉取该标签也不起作用:您从服务器获得响应,但无法执行任何操作。我不知道 windows 和 servercore 映像在一般情况下和 RDP 方面有何不同,最重要的是我绝不是 windows 专家。 到目前为止我的经验(使用 xfreerdp 作为客户端):

  • windows/servercore:1607 cexecsvc 正在运行,端口 3389 未侦听
  • windows/servercore:1709 可以连接到 RDP,但执行应用程序会导致 ERRINFO_LOGOFF_BY_USER
  • windows/servercore:1709_KB4074588 的行为与 1709 相同

研究还表明需要禁用远程执行白名单(不知道正确名称)。

  • reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" /v fAllowUnlistedRemotePrograms /t REG_DWORD /d 1
  • reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList" /v fDisabledAllowList /t REG_DWORD /f /d 1

阅读 brief about sessions,desktops and stations 后,我编写了一个枚举会话的快速测试(参见 LsaEnumerateLogonSessionsLsaGetLogonSessionData)并看到,而正常的 RDP 会话显示了许多(为什么?不知道)会话同一个用户,其中一些是交互式的(在我的情况下为 10 - CachedInteractive)Docker 实例中的控制台显示类型 5(代理 - 不支持)的 ContainerAdministrator 用户的单个会话,所以据我所知,这是不可能的从此会话中获取交互式桌面。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。