本地浏览器使用Docker容器中的Jupyter

本地浏览器访问Docker容器内的tensorboard可视化内容

1.docker容器端口映射
docker run --gpus all -it --name dc -p 6166:6166/tcp -v /data0/data/:/app --shm-size 10240m image /bin/bash

释意:

gpus all:使docker能支持GPU,要用gpu必须用这种方式(版本19.03以上);

-i:–interactive,保持标准输入始终开启着,保证容器能收到STDIN;

-t:–tty,为创建的容器分配一个伪tty,相当于提供了交互式shell;

–name:这个容器的名字,建议加上自己标识,明确是谁的容器;

-v:挂载一个host的目录到容器内,可以挂载多个目录;

-p:端口映射,容器的6166端口映射到主机的6166;

–shm-size=1024m :可选的,有时候shared-memory不足,可以通过这个参数指定;

2.在容器中安装并配置jupyter notebook
#安装jupyter 
pip install jupyter

#配置jupyter notebook可远程访问
jupyter-notebook --generate-config
#执行命令后结果:
(base) root@2e1a21cd238f:/# jupyter-notebook --generate-config
Overwrite /root/.jupyter/jupyter_notebook_config.py with default config? [y/N]y
Writing default config to: /root/.jupyter/jupyter_notebook_config.py、

#配置密码
(base) root@2e1a21cd238f:/# ipython
Python 3.8.3 (default, Jul  2 2020, 16:21:59)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from notebook.auth import passwd

In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:***********************'
#得到密钥,复制备用

#配置jupyter
vi /root/.jupyter/jupyter_notebook_config.py
# 在jupyter_notebook_config.py 文件填入下面配置:
# 允许通过任意绑定服务器的ip访问
c.NotebookApp.ip = '*'
 # 用于访问的端口
c.NotebookApp.port = 6166 #注意这里与前面启动容器的端口要一致
 # 不自动打开浏览器
c.NotebookApp.open_browser = False
 #允许远程访问
c.NotebookApp.allow_remote_access = True 
 # 设置登录密码
c.NotebookApp.password = u'sha1:**********' 
# 复制jupyter_notebook_config.json中的sha1码
3.启动jupyter
jupyter notebook --ip=0.0.0.0 --allow-root
4.在本地打开cmd,ssh连接到服务器:
ssh -L 6006:127.0.0.1:6166 root@10.10.10.10 -p 2212

释意:

6006为本地的端口,6166为docker容器中开启tensorboard服务的端口号的主机映射端口;

root为你的用户名,10.10.10.10为你的服务器IP地址,2212为服务器的ssh端口;

连接到服务器后,会提示输入密码,然后输入即可。

4.打开本地浏览器远程连接docker容器中的jupyter

在本地浏览器打开页面:http://127.0.0.1:6006/,即可访问服务器里的docker容器jupyter。

登录后输入你设置的密码即可登录。

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值