Authenticating Jupyter notebook on docker

Viewed 9645

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

5 Answers

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'

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

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. Only then I could open the notebook within docker. Before that, I entered the token produced by docker but always got "invalid credentials".

Related