创建到运行Jupyter Notebook的远程Docker容器的ssh隧道 [英] Create ssh tunnel to remote docker container running Jupyter Notebook

查看:436
本文介绍了创建到运行Jupyter Notebook的远程Docker容器的ssh隧道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一条从我的计算机到远程服务器的SSH隧道,再到运行Jupyter Notebook的Docker容器(计算机>服务器> Docker容器),使我可以在计算机的浏览器中运行Jupyter Notebook.

I'd like to create a ssh tunnel from my computer to a remote server to a docker container running Jupyter Notebook (computer>server>Docker container) that allows me to run a Jupyter Notebook in my browser on my computer.

Docker容器托管在运行OS X(El Capitan)的计算机上. Docker使用默认计算机IP:192.168.99.100.

The Docker container is hosted on a machine running OS X (El Capitan). Docker is using the default machine IP: 192.168.99.100.

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.11.1  

我能够实际坐在运行Docker容器的服务器上,并使用我的浏览器(192.168.99.100:8888)从该Docker容器创建Jupyter Notebook.这可以验证我的Docker端口绑定是否正常工作,以及我是否在正确运行Jupyter Notebook.

I am able to physically sit at the server running the Docker container and use my browser (192.168.99.100:8888) to create Jupyter Notebooks from that Docker container. This verifies that my Docker port bindings work and that I'm running the Jupyter Notebook correctly.

但是,我不知道如何建立从客户端计算机到该远程计算机的Docker容器的ssh隧道,以及如何在客户端计算机上的浏览器中启动Jupyter Notebook.

However, I don't know how to establish a ssh tunnel from a client machine to that remote machine's Docker container and launch a Jupyter Notebook in my browser on the client machine.

输出来自:

$ docker ps

产生以下内容:

CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS              PORTS                              NAMES
48a8ac126c72        kubu4/bioinformatics:v11   "/bin/bash"         55 minutes ago      Up 55 minutes       8787/tcp, 0.0.0.0:8888->8888/tcp   stupefied_pasteur

当我尝试在客户端计算机(localhost:8888)的浏览器中启动Jupyter Notebook时,尝试创建到远程计算机Docker容器的ssh隧道导致在终端中出现以下错误消息:

My attempts at creating a ssh tunnel to the remote machine's Docker container results in the following error message in Terminal when I try to launch the Jupyter Notebook in my browser on the client machine (localhost:8888):

channel 3: open failed: connect failed: Connection refused

我目前正在.ssh/config文件中使用以下命令创建隧道:

I'm currently using the following in my .ssh/config file to create the tunnel:

Host tunnel3
HostName remote.ip.address
User user
ControlMaster auto
ServerAliveInterval 30
ServerAliveCountMax 3
LocalForward localhost:8888 localhost:8888

如果我在远程计算机上的Docker容器之外的远程计算机上运行Jupyter Notebook,则可以使用此隧道配置在客户端浏览器中成功启动Jupyter Notebook.

I can use this tunneling configuration to successfully launch Jupyter Notebooks in my client browser if I run the Jupyter Notebook on the remote machine outside of the Docker container that's on the remote machine.

仅提供更多信息,这是我在远程计算机的Docker容器中启动Jupyter Notebook时的输出:

Just for added info, this is the output when I launch the Jupyter Notebook in the remote machine's Docker container:

$ jupyter notebook
[I 18:23:32.951 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 18:23:33.072 NotebookApp] Serving notebooks from local directory: /usr/local/bioinformatics
[I 18:23:33.073 NotebookApp] 0 active kernels 
[I 18:23:33.073 NotebookApp] The Jupyter Notebook is running at: http://0.0.0.0:8888/
[I 18:23:33.074 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

推荐答案

我知道了! 啊哈!"当时我想起运行Docker的远程机器是OS X(El Capitan).我所有的Docker构建/测试都是在Linux(Ubuntu 14.04)机器上执行的.事实证明,差异对于解决此问题至关重要.

I figured it out! The "A-ha!" moment was remembering that the remote machine running Docker was OS X (El Capitan). All my Docker builds/tests had been performed on a Linux (Ubuntu 14.04) machine. The difference, it turns out, is critical to solving this problem.

在Ubuntu上安装的Docker允许您使用"localhost"来寻址Docker容器.在OSX上安装的Docker会生成一个IP地址,用于寻址Docker容器.

Docker installs on Ubuntu allow you to use "localhost" to address the Docker container. Docker installs on OSX generate an IP address to use to address the Docker container.

意识到这一点,我在客户端计算机上的.ssh/config文件中更改了ssh隧道配置.

Realizing this, I changed my ssh tunneling configuration in the.ssh/config file on my client computer.

旧隧道配置:

Host tunnel3
HostName remote.ip.address
User user
ControlMaster auto
ServerAliveInterval 30
ServerAliveCountMax 3
LocalForward localhost:8888 localhost:8888

新的隧道配置:

Host tunnel3
HostName remote.ip.address
User user
ControlMaster auto
ServerAliveInterval 30
ServerAliveCountMax 3
LocalForward localhost:8888 192.168.99.100:8888

通过此更改,我可以使用URL栏中的localhost:8888在客户端浏览器中成功创建/使用实际上托管在远程计算机的Docker容器中的Jupyter Notebook.

With this change, I can successfully create/use Jupyter Notebooks in my client browser that are actually hosted in the Docker container on the remote machine, using localhost:8888 in the URL bar.

这篇关于创建到运行Jupyter Notebook的远程Docker容器的ssh隧道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆