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

Joh*_*van 6 containers remote-desktop terminal-services docker 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
Run Code Online (Sandbox Code Playgroud)

注意:由于它是 Windows 映像,因此我已将 Docker Desktop 切换到 Windows 容器(参考:Docker:“清单列表条目中没有 windows/amd64 的匹配清单”

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

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

容器运行成功;但我无法连接到它(mstsc与主机设备上的计算机名称一起使用127.0.0.1:3390;甚至执行 a 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上看到过类似的问题;尽管再次询问,因为这是针对服务器而不是桌面,但该问题有关已尝试内容的信息较少,并且没有答案。因此,我希望这不会被视为重复。

Giu*_*lli 8

您用于构建 Dockerfile 的参考指出,在 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 添加“HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services”/v fAllowUnlistedRemotePrograms /t REG_DWORD /d 1
  • reg 添加“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList” /v fDisabledAllowList /t REG_DWORD /f /d 1

在阅读了有关会话、桌面和工作站的简介后,我编写了一个枚举会话的快速测试(请参阅LsaEnumerateLogonSessionsLsaGetLogonSessionData),并发现,虽然普通的 RDP 会话显示同一用户的许多(为什么?不知道)会话,但其中一些是交互式(在我的例子中为 10 - CachedInteractive)Docker 实例中的控制台显示类型 5(代理 - 不支持)的 ContainerAdministrator 用户的单个会话,因此据我了解,无法从此会话中获取交互式桌面。