问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/48875436/jupyter-password-and-docker