'Authenticating Jupyter notebook on docker
I am trying to install jupyter notebook docker container on my Mac laptop. 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.
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
Solution 1:[1]
The stdout of the container will give you a special URL that has a token for you to login with. You can either run in the foreground (without -d) or just checking the current container logs with 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
Solution 2:[2]
You can also disable the token or add a customised token with the --NotebookApp.token='' parameter of the start-notebook.sh script. 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'
Solution 3:[3]
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
Solution 4:[4]
Thanks for your tips, I simply found my token with the command docker logs <name of the container>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andy Shinn |
| Solution 2 | |
| Solution 3 | Laurens |
| Solution 4 | Nicolas Chaillou |
