Jupyter密码和Docker

Lag*_*aer 2 docker jupyter-notebook

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

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.

mim*_*ros 8

找到了两种可能的解决方案,我测试了两者并且都有效。

jupyter 核心:4.6.3
jupyter-笔记本:6.0.3

设置密码

“添加选项-e PASSWORD=password来设置环境变量。设置的密码就是 jupyter 登录的密码。” [1] 当docker run

environment:
    - PASSWORD=password
Run Code Online (Sandbox Code Playgroud)

使用 Docker Compose 时。然后输入密码

设置令牌

“……已经存在一种在启动 Jupyter notebook Docker 容器时设置令牌的简单方法:-e JUPYTER_TOKEN="easy; it's already there"。实际上,如果您export JUPYTER_TOKEN='easy'在本地环境中,然后使用 docker 启动容器run --rm -d --name democontainer -p 9999:8888 -e JUPYTER_TOKEN jupyter/base-notebook(相当于-e JUPYTER_TOKEN=$JUPYTER_TOKEN),事情就更容易了. 然后你可以通过 open 自动启动到笔记本中http://localhost:9999?token=${JUPYTER_TOKEN}。H/t @minrk ……”[2]

使用 Docker Compose 时

environment:
    - JUPYTER_TOKEN=easy
Run Code Online (Sandbox Code Playgroud)

然后只运行http://localhost:9999?token=easy或自动化更多......

[1]访问运行在 nvidia-docker 容器中的 jupyter notebook 需要登录密码

[2] https://blog.ouseful.info/2019/02/05/on-not-faffing-around-with-jupyter-docker-container-auth-tokens/

  • 由于某种原因,第一个解决方案对我不起作用。第二个有效。谢谢! (5认同)

小智 5

使用ipython终端创建哈希密码

from notebook.auth import passwd
passwd()
Run Code Online (Sandbox Code Playgroud)

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

RUN jupyter notebook --generate-config
RUN echo "c.NotebookApp.password='sha1:***'">>/root/.jupyter/jupyter_notebook_config.py
Run Code Online (Sandbox Code Playgroud)

由于我是唯一使用笔记本电脑的人,所以我坚持到底。