Main Content

创建与远程应用程序和容器的加密连接

If you want to create a encrypted connection between your local client machine and an application running on a remote machine, you can use SSH tunneling. Some applications transmit information without adding encryption. To access this type of applications over the internet using encryption, use SSH tunneling, also called SSH port forwarding. Doing so provides an encrypted connection between the local client machine and the remote application such as a container session. If the remote host or the local machine is protected by a firewall, you must use SSH tunnelling.

SSH隧道

这些说明向您展示了如何将客户机上的端口转发到远程计算机上的端口。例如,如果您在端口之间创建端口转发机制5903在您的客户端机器和端口上5902在远程计算机上,所有连接与localhost:5903自动转发到远程主机:5902, 在哪里localhostand远程主机分别是本地和远程计算机的名称或IP地址。因此,如果您设置了端口5902on the remote machine to allow you to access a container session, then you can access the container session directly fromlocalhost:5903。设置SSH隧道后,对客户端端口和容器会话之间的所有通信进行了加密。

在A上使用腻子WindowsClient

如果您使用腻子连接到远程计算机,请使用菜单选项更改设置添加新的转发端口,可以右键单击“ Putty会话”的标题栏。在里面油灰配置对话框,下Category, 选择联系>SSH>Tunnels

要通过VNC连接,请将隧道设置为容器端口5901(默认VNC端口)。

  • 在“源端口”字段中,在开始时输入客户端计算机上的自由端口5900, 例如5903

  • 在目标字段中,输入您连接到容器端口的相关主机端口5901当您执行docker run例如,命令localhost:5902。请注意,您必须使用localhost而不是主机机器的名称。这是因为目标字段解释localhost作为目标计算机的名称。

要通过Web浏览器连接,请为容器端口设置隧道6080(默认NOVNC端口)。

  • 在源端口字段中,输入客户端计算机上的自由端口,例如6082

  • 在目标字段中,输入您连接到容器端口的相关主机端口6080当您执行docker run例如,命令Localhost:6081。请注意,您必须使用localhost而不是主机实例的名称。这是因为目标字段解释localhost作为目标计算机的名称。

如果您使用多个容器或在客户端计算机上运行VNC服务器,则必须在客户端计算机上增加源端口,直到找到一个免费端口,例如5905or6085

Using a Command-Line Interface

If you are using a command-line interface to SSH tunnel to a container port, use a command of this form:

ssh -L clientport:hostport ubuntu@MyRemoteMachine

客户端是客户机器上的免费端口5903or6082Hostport执行时,是您连接到容器端口的主机端口docker run例如,命令localhost:5902orLocalhost:6081。请注意,您必须使用localhost而不是主机实例的名称。This is because theHostport参数解释localhost作为主机机器的名称。

例如,使用以下命令:

SSH -L 5903:localhost:5902 ubuntu@mycompanydgx1

如果您在客户端计算机上运行VNC服务器,则必须增加客户端端口,直到找到免费端口,例如5905or6085

Connect to Container Desktop

要连接到容器桌面docker run, 例如:

Docker Run -It -RM -P 5902:5901 -P 6081:6080 -shm -Size = 512M Mathworks/MATLAB:R2021A -VNC
国旗在哪里-vnc启动VNC服务器和标志-p映射Docker主机端口5902and6081到容器端口5901and6080, 分别。有关运行MATLAB的更多信息®container and using these flags, seeMATLABContainer on Docker Hub

设置SSH隧道后,要在本地计算机上使用Web浏览器进行连接,请使用URL:

http://localhost:6082

请注意,您必须使用localhost而不是主机实例的名称。

如果您在制作隧道时会增加客户端端口,请使用适当的客户端端口号,例如6085

设置SSH隧道后,要与VNC连接,请使用VNC客户端连接到客户端上适当的显示端口,例如:

Localhost:3

请注意,您必须使用localhost而不是主机实例的名称。

如果您在制作隧道时会增加客户端端口,请使用适当的客户端显示端口号,例如5对于港口5905

Related Topics