简体   繁体   English

VSCode:如何通过远程服务器在 docker 容器中运行 Jupyter notebook?

[英]VSCode: How to run a Jupyter notebook in a docker container, over a remote server?

I can use the docker extension, and right click 'attach shell' to a running container.我可以使用 docker 扩展,然后右键单击“附加外壳”到正在运行的容器。 However, my Jupyter notebooks is not running in that container.但是,我的 Jupyter notebooks 并未在该容器中运行。

I tried googling how to run a jupyter notebook in a docker container, but I didn't get any results.我尝试用谷歌搜索如何在 docker 容器中运行 jupyter notebook,但没有得到任何结果。

If it makes a difference, I am trying to run my notebook in a docker container on a remote server (using VS Code remote ssh to log in)如果它有所作为,我正在尝试在远程服务器上的 docker 容器中运行我的笔记本(使用 VS Code 远程 ssh 登录)

Edit:编辑:

I also tried running我也试过跑步

!docker exec -ti {container name} bash

In jupyter, but that cell just hangs.在 jupyter 中,但那个单元格只是挂起。 When I stop the cell, the notebook still does not run in the container.当我停止单元格时,笔记本仍然没有在容器中运行。

Update 31.08.2022: The original approach now may cause Docker error: 2022 年 8 月 31 日更新:原来的方法现在可能会导致 Docker 错误:

standard_init_linux.go:228: exec user process caused: no such file or directory

Which is fixed if you're using system package instead of raw download from repo.如果您使用系统 package 而不是从 repo 原始下载,则该问题已修复。 In case of Ubuntu:如果是 Ubuntu:

RUN apt-get install tini

the rest is the same: rest 是相同的:

RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]

Just came to the same problem.刚遇到同样的问题。 It appeared that you cannot run Jupyter from a container out of the box.看来您无法从开箱即用的容器中运行 Jupyter。 But this link helped me.但是这个链接帮助了我。 Basically what you need is:基本上你需要的是:

  1. Add this to your dockerfile:将此添加到您的 dockerfile:
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes.
ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0", "--allow-root"]

This will start jupyter inside a container on port 8888. So don't forget to expose this port in your docker-compose or docker run.这将在端口 8888 上的容器内启动 jupyter。所以不要忘记在 docker-compose 或 docker 运行中公开此端口。

This worked for me in my local docker. I can assume that for SSH docker you need to forward 8888 port during you SSH connection from remote to your local host.这在我的本地 docker 中对我有用。我可以假设对于 SSH docker,您需要在 SSH 从远程连接到本地主机期间转发 8888 端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Docker 容器中将 Spyder 连接到远程 Jupyter Notebook - Connecting Spyder to Remote Jupyter Notebook in a Docker Container 连接到在远程服务器上的docker中运行的jupyter Notebook - Connect to jupyter notebook running in docker on a remote server VSCODE如何在远程服务器docker容器的conda环境中调试python - VSCODE how to debug python in conda environment in docker container in remote server 远程访问在 WSL 2 上的 docker 容器中运行的 jupyter notebook - Remote access to jupyter notebook running in docker container on WSL 2 创建到运行Jupyter Notebook的远程Docker容器的ssh隧道 - Create ssh tunnel to remote docker container running Jupyter Notebook 如何使用 docker 和 ubuntu 运行 jupyter notebook? - How to run jupyter notebook using docker with ubuntu? 如何在 docker 的特定文件夹中运行 jupyter notebook - How to run a jupyter notebook at a particular folder in docker Docker - 无法运行 Jupyter 笔记本 - KeyError: 'allow_remote_access' - Docker - unable to run Jupyter notebook - KeyError: 'allow_remote_access' 如何从服务器上的Docker访问Jupyter Notebook? - How to access jupyter notebook from docker on server? 在远程服务器上的 docker 中运行的 jupyter 笔记本:keras 不使用 gpu - jupyter notebook running in docker on remote server: keras not using gpu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM