Jupyter密码和Docker [英] Jupyter password and Docker

查看:541
本文介绍了Jupyter密码和Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要更改/设置Jupyter服务器的密码,请按照此处的说明进行操作:

http://jupyter-notebook .readthedocs.io/en/latest/public_server.html#preparing-a-hashed-password

我在本地ipython环境中执行此操作.需要注意的一件事是,每次我为相同的密码重新运行passwd()命令时,都会以某种方式得到不同的哈希值,但是我认为这是预期的行为.

无论如何.我得到了哈希,然后在Dockerfile中有这样一行:

ENV PW_HASH="u'sha1:salt:hash'"

以及在我拥有的jupyter笔记本的启动脚本中

echo "c.NotebookApp.password = ${PW_HASH}" >> ${CONFIG_PATH}

然后 jupyter notebook --allow-root -y --no-browser --ip=0.0.0.0 --config=${CONFIG_PATH}

但是,如果我随后通过以下方式运行docker容器

docker run -it -p 8888:8888 <container-name>

虽然确实启动了jupyter,并允许我通过localhost:8888在浏览器中进行连接,但它不会接受我只是通过其哈希设置的密码.

奇怪的是,当我添加SSL证书的其他步骤时,它确实起作用(并转到 https://localhost:8888 ).这是怎么回事?

PS:我知道拥有一个密码但没有SSL是很粗略的.我只是一步一步地测试它,想知道为什么没有SSL部分就无法使用它.

解决方案

使用ipython终端创建哈希密码

from notebook.auth import passwd
passwd()

它将提示您两次输入密码,并创建哈希密码, 并在Docker文件中添加以下行

RUN jupyter notebook --generate-config
RUN echo "c.NotebookApp.password='sha1:***'">>/root/.jupyter/jupyter_notebook_config.py

由于我是唯一一个使用笔记本的人,所以我只是坚持到底.

For changing / setting the password of a Jupyter server, I follow the instructions here:

http://jupyter-notebook.readthedocs.io/en/latest/public_server.html#preparing-a-hashed-password

I do this in my local ipython environment. One thing to note is that somehow I get different hashes every time I re-run the passwd() command for the same password, but I assume that's intended behavior.

Anyway. I get the hash, and then I have a line like this in a Dockerfile:

ENV PW_HASH="u'sha1:salt:hash'"

and in the start-up script for the jupyter notebook I have

echo "c.NotebookApp.password = ${PW_HASH}" >> ${CONFIG_PATH}

and then jupyter notebook --allow-root -y --no-browser --ip=0.0.0.0 --config=${CONFIG_PATH}

However, if I then run the docker container via

docker run -it -p 8888:8888 <container-name>

while it does start up jupyter and allows me to connect in my browser via localhost:8888, it won't accept the password I just set via its hash.

Strangely, it does work when I add the additional step of the SSL certificates (and go to https://localhost:8888). What's going on here?

PS: I know that having a password but no SSL is sketchy. I'm just testing it out step by step and wonder why it won't work without the SSL part.

解决方案

Create a hashed password, using the ipython terminal

from notebook.auth import passwd
passwd()

It will promote you to enter the passwd twice, and create the hashed password, and add following lines in the Docker file

RUN jupyter notebook --generate-config
RUN echo "c.NotebookApp.password='sha1:***'">>/root/.jupyter/jupyter_notebook_config.py

Since I am the only person using the notebook, I just sticked to the root.

这篇关于Jupyter密码和Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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