在Docker容器中将Spyder连接到远程Jupyter Notebook [英] Connecting Spyder to Remote Jupyter Notebook in a Docker Container

查看:547
本文介绍了在Docker容器中将Spyder连接到远程Jupyter Notebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图将Spyder连接到在远程服务器上运行的docker容器,一次又一次失败.这是我要实现的目标的简要示意图:

I have been trying to connect Spyder to a docker container running on a remote server and failing time and again. Here is a quick diagram of what I am trying to achieve:

当前,我正在使用

docker run --runtime=nvidia -it --rm --shm-size=2g -v /home/timo/storage:/storage -v /etc/passwd:/etc/passwd -v /etc/group:/etc/group --ulimit memlock=-1 -p 8888:8888 --ipc=host ufoym/deepo:all-jupyter

所以我正在端口8888上转发.然后在docker容器中运行

so I am forwarding on port 8888. Then inside the docker container I am running

jupyter notebook --no-browser --ip=0.0.0.0 --port=8888 --allow-root --notebook-dir='/storage' 

好,现在是Spyder的一部分-按照说明

OK, now for the Spyder part - As per the instructions here, I go to ~/.local/share/jupyter/runtime, where I find the following files:

kernel-ada17ae4-e8c3-4e17-9f8f-1c029c56b4f0.json  nbserver-11-open.html  nbserver-21-open.html  notebook_cookie_secret
kernel-e81bc397-05b5-4710-89b6-2aa2adab5f9c.json  nbserver-11.json       nbserver-21.json

我不知道要拿哪个,我将它们 all 复制到我的本地计算机上.

Not knowing which one to take, I copy them all to my local machine.

我现在转到Consoles-> Connect to a Existing Kernel,这会给我一个"Connect to a Existing Kernel"窗口,我将这样填写(当然使用我的实际远程IP地址):

I now go to Consoles->Connect to an Existing Kernel, which gives me the "Connect to an Existing Kernel" window which I fill out as so (of course using my actual remote IP address):

(这里我为Connection info:选择了第一个json文件).我按Enter键,Spyder变黑并崩溃.

(here I have chosen the first of the json files for Connection info:). I hit enter and Spyder goes dark and crashes.

无论我选择哪个连接信息文件,都会发生这种情况.所以,我的问题是:

This happens regardless of which connection info file I choose. So, my questions are:

1:我是否正确执行了所有这些操作?我找到了很多有关如何连接到远程服务器的说明,但是到目前为止,还没有专门针对远程服务器上的 docker 上的jupyter笔记本进行连接的说明.

1: Am I doing all of this correctly? I have found lots of instructions for how to connect to remote servers, but not so far for specifically connecting to a jupyter notebook on a docker on a remote server.

2:如果是,那么我还能做些什么来解决我遇到的问题?

2: If yes, then what else can I do to troubleshoot the issues I am encountering?

我还应该注意,通过本地计算机上的浏览器连接到Jupyter Notebook没有问题.只是我更愿意将Spyder作为我的IDE.

I should also note that I have no problems connecting to the Jupyter Notebook through the browser on my local machine. It's just that I would prefer to be working with Spyder as my IDE.

非常感谢!

推荐答案

这不是一个解决方案,但sshfs可能会有所帮助

This isn't a solution so much as a work around, but sshfs might be of help

使用sshfs将远程计算机的主目录挂载在本地目录上,然后您的Spyder本地副本可以像对待本地文件一样编辑该文件.

Use sshfs to mount the remote machine's home directory on a local directory, then your local copy of Spyder can edit the file as if it were a local file.

sshfs remotehost.com:/home/user/ ./remote-host/

当您在Spyder中单击保存时,通常需要大约半秒钟将更改上传到AWS主机,这对我来说是可以接受的延迟.当需要运行代码时,请使用ssh进入远程计算机,然后从IPython shell运行代码.它不优雅,但确实可以.

It typically takes about half a second to upload the changes to an AWS host when you I hit save in Spyder, which is an acceptable delay for me. When it's time to run the code, ssh into the remote machine, and run the code from an IPython shell. It's not elegant, but it does work.

我不希望这是最好的答案,但是也许您可以将其用作权宜之计.

I'm not expecting this to be the best answer, but maybe you can use it as a stopgap solution.

这篇关于在Docker容器中将Spyder连接到远程Jupyter Notebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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