【问题标题】:Connect to jupyter notebook running in docker on a remote server连接到远程服务器上的 docker 中运行的 jupyter notebook
【发布时间】:2019-07-01 12:25:33
【问题描述】:

我在建立从本地计算机到我在 docker 容器中的远程服务器上运行的 jupyter notebook 实例的连接时遇到问题。

到目前为止我做了什么:

我用ssh username@remoteHostIp连接到远程服务器

我运行 docker container ls 以确保我的容器尚未运行

现在我用docker run -it -p 8888:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning启动我的容器

我现在在我的容器中使用终端并启动一个无浏览器的 jupyter notebook 实例

jupyter notebook --no-browser --port=8889 --allow-root

启动成功:

The Jupyter Notebook is running at:
[I 11:14:51.979 NotebookApp] system]:8889/

现在我在本地计算机上启动另一个 shell 并创建一个 ssh 隧道:

ssh -N -f -L localhost:8888:localhost:8889 username@ remote_host_name

我的 shell 几秒钟后返回以下内容:

channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused

我无法通过 localhost:8888/ 或 localhost:8889/ 访问 jupyter notebook

当我在 docker 容器外的远程服务器上运行 jupyter notebook 并创建 ssh 隧道时,一切正常。

一些附加信息: 远程服务器: 经销商编号:Ubuntu 说明:Ubuntu 16.04.3 LTS 发布时间:16.04 代号:xenial

我的本​​地机器在 osx moave 上运行

【问题讨论】:

  • 我也找到了这个this 线程,但我不确定这对我的问题有什么帮助,
  • 感谢您的回答,但以下命令对我不起作用。 jupyter notebook --no-browser --port=8889 --allow-root。一旦使用 --ip 0.0.0.0 运行它就可以正常工作。 jupyter notebook --ip 0.0.0.0 --port=8889 --allow-root

标签: docker jupyter-notebook ssh-tunnel


【解决方案1】:

首先你应该使用

连接到远程服务器
ssh username@remoteHostIp

连接到它后,您应该使用

运行 docker 容器
docker run -it -p 8080:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning

我在这里考虑端口 8888 是 jupyter notebook 端口,8080 是远程服务器端口

现在在本地机器上打开一个新的终端窗口,使用以下选项再次通过 SSH 连接到远程机器以设置端口转发。

ssh -N -L localhost:8000:localhost:8080 username@remoteHostIp

我在这里考虑端口 8000 是我的本地机器端口,而 8080 如上所述已经是远程服务器端口

现在通过本地浏览器访问远程 jupyter 服务器。打开浏览器并转到:

localhost:8000

【讨论】:

  • 但我看不到他是如何启动 jupyter 的?任何地方都没有“jupyter notebook”命令。
  • 在运行 docker 命令时,jupyter notebook 将启动,因为我们在该命令中将远程服务器端口(8080)连接到 jupyter notebook 端口(8888)
  • 所以,容器 waleedka/modern-deep-learning 在容器启动时运行的脚本中有一个类似“./jupyter notebook”的命令?仅仅因为你打开容器上的端口到主机,jupyter 不必自动启动。
  • 为此,我们需要在创建映像之前将 run_jupyter.sh 脚本文件保存在 Dockerfile 中,例如 (CMD ["/run_jupyter.sh", "--allow-root"] )。创建镜像后,当我们运行容器时,这将允许我们运行 jupyter notebook 并提供连接令牌
  • 对我有用 - 我没有看到 ssh-f 选项 --- 那是为了什么?
【解决方案2】:

我自己解决了这个问题,方法是连接到删除服务器并检查 docker 容器 IP 地址:docker inspect <container_name>。 然后我使用该 IP 地址创建 ssh 隧道:

ssh -N -f -L localhost:8889:dockerContainerIpAdress:8889 username@ remote_host_name

现在我可以在本地浏览器中使用 localhost:8889 连接到 jupyter notebook

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 2020-03-17
    • 2019-11-29
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2020-12-19
    • 2016-09-30
    • 2021-01-16
    相关资源
    最近更新 更多