Docker安装Jupyter
  1KhS53dKYrtp 2023年11月02日 28 0

1、准备工作

1.1、安装Docker

参考:https://docs.docker.com/engine/install/

1.2、选择镜像

Jupyter提供了多种用途的镜像,安装前需要阅读各类镜像的介绍,选择合适的镜像。参考:https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html

本文示例选择的镜像:jupyter/datascience-notebook:2023-06-01

2、正式安装

2.1、主机端口

本文示例: 8090, 通过8090映射容器中Jupyter Server的8888端口。

2.2、主机目录

Jupyter容器的默认工作目录为:/home/jovyan。容器工作目录映射主机目录为:/data/juypter

注意:本示例是将工作目录(/home/jovyan)下的work目录映射到/data/jupyter,如果在work目录之外创建的文件将不会映射到主机目录,而是保存在容器内部。

2.3、启动容器

docker run -d --name jupyter -v /data/jupyter:/home/jovyan/work -p 8090:8888 -e JUPYTER_ENABLE_LAB=yes  jupyter/datascience-notebook:2023-06-01

启动容器除了以上最基本的参数外,还有其它更多参数设置,参考:Common Features — Docker Stacks documentation (jupyter-docker-stacks.readthedocs.io)。

 Mounts a host machine directory as a folder in the container. This configuration is useful for preserving notebooks and other work even after the container is destroyed.You must grant the within-container notebook user or group (NB_UID or NB_GID) write access to the host directory (e.g., sudo chown 1000 /some/host/folder/for/work).

由于挂在主机目录到容器,所以需要对容器中的用户和用户组授于访问主机目录的权限,执行如下命令:

sudo chown 1000 /data/jupyter

2.4、查看token

通过容器日志命令:

docker logs juypter

日至输出:

Entered start.sh with args: jupyter lab
Executing the command: jupyter lab
[I 2023-07-20 08:18:23.968 ServerApp] Package jupyterlab took 0.0000s to import
[I 2023-07-20 08:18:23.994 ServerApp] Package jupyter_lsp took 0.0260s to import
[W 2023-07-20 08:18:23.995 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2023-07-20 08:18:23.998 ServerApp] Package jupyter_server_mathjax took 0.0029s to import
[I 2023-07-20 08:18:24.012 ServerApp] Package jupyter_server_terminals took 0.0136s to import
[I 2023-07-20 08:18:24.069 ServerApp] Package jupyterlab_git took 0.0562s to import
[I 2023-07-20 08:18:24.072 ServerApp] Package nbclassic took 0.0022s to import
[W 2023-07-20 08:18:24.075 ServerApp] A `_jupyter_server_extension_points` function was not found in nbclassic. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2023-07-20 08:18:24.076 ServerApp] Package nbdime took 0.0000s to import
[I 2023-07-20 08:18:24.077 ServerApp] Package notebook_shim took 0.0000s to import
[W 2023-07-20 08:18:24.077 ServerApp] A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2023-07-20 08:18:24.078 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2023-07-20 08:18:24.083 ServerApp] jupyter_server_mathjax | extension was successfully linked.
[I 2023-07-20 08:18:24.088 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2023-07-20 08:18:24.094 ServerApp] jupyterlab | extension was successfully linked.
[I 2023-07-20 08:18:24.094 ServerApp] jupyterlab_git | extension was successfully linked.
[W 2023-07-20 08:18:24.098 NotebookApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2023-07-20 08:18:24.098 NotebookApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2023-07-20 08:18:24.102 ServerApp] nbclassic | extension was successfully linked.
[I 2023-07-20 08:18:24.102 ServerApp] nbdime | extension was successfully linked.
[I 2023-07-20 08:18:24.103 ServerApp] Writing Jupyter server cookie secret to /home/jovyan/.local/share/jupyter/runtime/jupyter_cookie_secret
[I 2023-07-20 08:18:24.582 ServerApp] notebook_shim | extension was successfully linked.
[I 2023-07-20 08:18:24.738 ServerApp] notebook_shim | extension was successfully loaded.
[I 2023-07-20 08:18:24.744 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2023-07-20 08:18:24.745 ServerApp] jupyter_server_mathjax | extension was successfully loaded.
[I 2023-07-20 08:18:24.747 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2023-07-20 08:18:24.748 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.11/site-packages/jupyterlab
[I 2023-07-20 08:18:24.748 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 2023-07-20 08:18:24.749 LabApp] Extension Manager is 'pypi'.
[I 2023-07-20 08:18:24.753 ServerApp] jupyterlab | extension was successfully loaded.
[I 2023-07-20 08:18:24.759 ServerApp] jupyterlab_git | extension was successfully loaded.
[I 2023-07-20 08:18:24.766 ServerApp] nbclassic | extension was successfully loaded.
[I 2023-07-20 08:18:24.875 ServerApp] nbdime | extension was successfully loaded.
[I 2023-07-20 08:18:24.877 ServerApp] Serving notebooks from local directory: /home/jovyan
[I 2023-07-20 08:18:24.877 ServerApp] Jupyter Server 2.6.0 is running at:
[I 2023-07-20 08:18:24.877 ServerApp] http://90bcacb5a09b:8888/lab?token=ef9459f4079ab48f36cd21b6b5977aee43074b0180c6974e
[I 2023-07-20 08:18:24.877 ServerApp]     http://127.0.0.1:8888/lab?token=ef9459f4079ab48f36cd21b6b5977aee43074b0180c6974e
[I 2023-07-20 08:18:24.877 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2023-07-20 08:18:24.881 ServerApp] 
    
    To access the server, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html
    Or copy and paste one of these URLs:
        http://90bcacb5a09b:8888/lab?token=ef9459f4079ab48f36cd21b6b5977aee43074b0180c6974e
        http://127.0.0.1:8888/lab?token=ef9459f4079ab48f36cd21b6b5977aee43074b0180c6974e

如图:绿色框是访问token

Docker安装Jupyter_Docker


3、开始工作

3.1、访问工作台

打开浏览器输入:http://127.0.0.1:8080/lab 如下图所示。

注意:8080端口是容器8888端口映射的主机端口。

Docker安装Jupyter_Docker_02

3.2、Token登录

首次使用,请输入token进行登录

3.2、修改密码

由于token不便于记忆,首次登录前建议直接通过 token来修改密码,如图:

Docker安装Jupyter_Juypter_03


3.4、工作台

登录成功之后,将进入jupyter的工作台。

注意:安装的镜像不同,支持的功能有所不同。

Docker安装Jupyter_Docker_04

3.5、演示示例

工作台中选择:Notebook下的 Python3(ipykernel),会创建一个.ipynb文件。

注意:如果提示没有权限,请参考2.3中主机目录授权给容器用户和用户组。

Docker安装Jupyter_Docker_05

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  wwLZeziuqjLR   2023年12月11日   30   0   0 Dockercentos
  MCWYWqSAMsot   2023年12月11日   31   0   0 Docker
  LE2wsiBPlOhg   2023年12月06日   31   0   0 Dockercentos
  DnoStTHsc0vp   2023年12月11日   23   0   0 Docker
  wwLZeziuqjLR   2023年12月08日   97   0   0 Dockercentosbash
  wwLZeziuqjLR   2023年12月07日   33   0   0 Dockercentos