简体   繁体   English

在 docker 上验证 Jupyter notebook

[英]Authenticating Jupyter notebook on docker

I am trying to install jupyter notebook docker container on my Mac laptop.我正在尝试在我的 Mac 笔记本电脑上安装 jupyter notebook docker 容器。 With the following options使用以下选项

docker run -dit --rm -p 8888:8888 gcr.io/tensorflow/tensorflow

The container starts up and I can assess it on http://[cointainer-IP]:8888 as expected.容器启动,我可以按预期在http://[cointainer-IP]:8888上对其进行评估。

However it takes me to an authentication screen and asks for a token.但是,它会将我带到身份验证屏幕并要求提供令牌。 How do i get the token, which log should I look for in the docker container我如何获取令牌,我应该在 docker 容器中查找哪个日志

The stdout of the container will give you a special URL that has a token for you to login with.容器的stdout将为您提供一个特殊的 URL,该 URL 有一个令牌供您登录。 You can either run in the foreground (without -d ) or just checking the current container logs with docker logs <container_id> .您可以在前台运行(不带-d )或仅使用docker logs <container_id>检查当前容器日志。 There, you should see output like the following:在那里,您应该看到如下输出:

[I 16:57:05.859 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 16:57:05.871 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 16:57:05.877 NotebookApp] Serving notebooks from local directory: /notebooks
[I 16:57:05.877 NotebookApp] 0 active kernels 
[I 16:57:05.877 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=42685cc246e6571c0f16417327fbf4c398061125c00edea5
[I 16:57:05.877 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:57:05.878 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=42685cc246e6571c0f16417327fbf4c398061125c00edea5

You can also disable the token or add a customised token with the --NotebookApp.token='' parameter of the start-notebook.sh script.您还可以禁用令牌或使用start-notebook.sh脚本的--NotebookApp.token=''参数添加自定义令牌。 Coping the token from the Terminal often causes errors and is uncomfortable.从终端处理令牌通常会导致错误并且不舒服。

Disable token禁用令牌

Easily as follows:轻松如下:

docker run -d -p 8888:8888 jupyter/pyspark-notebook start-notebook.sh --NotebookApp.token=''

Customised Token定制代币

However, this is not recommended and you have the option to define an easy password:但是,不建议这样做,您可以选择定义简单密码:

docker run -d -p 8888:8888 jupyter/pyspark-notebook start-notebook.sh --NotebookApp.token='MY_EASY_PASSWORD'

I have written the following code for myself to automatically open a browser and enter authentication:我为自己编写了以下代码来自动打开浏览器并输入身份验证:

docker exec -it <docker container name> bash -c 'jupyter notebook list' | grep http | cut -f1 -d ' ' | xargs xdg-open

Works on Ubuntu 18.04适用于 Ubuntu 18.04

感谢您的提示,我只是使用命令docker logs <name of the container>找到了我的令牌

Run the following commands and copy the container ID number:运行以下命令并复制容器 ID 号:

docker ps -a

docker logs <containerid>

From the log records, look for "To access the server .." like this:从日志记录中,查找“To access the server ..”,如下所示:

http://127.0.0.1:8888/lab?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx http://127.0.0.1:8888/lab?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Just in case someone else is in my situation: the only way I could solve this (thanks to a comment by @user3780173 in the accepted answer) was to close another instance of jupyter that I had running in my host machine.以防万一其他人遇到我的情况:我可以解决这个问题的唯一方法(感谢@user3780173 在接受的答案中的评论)是关闭我在主机上运行的另一个 jupyter 实例。 Only then I could open the notebook within docker.只有这样我才能打开 docker 内的笔记本。 Before that, I entered the token produced by docker but always got "invalid credentials".在此之前,我输入了 docker 生成的令牌,但总是得到“无效凭据”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM