After your docker run command, a hyperlink should be automatically generated. It looks something like this: http://localhost:8888/?token=f3a8354eb82c92f5a12399fe1835bf8f31275f917928c8d2 :: /home/jovyan/work
If you want to get the link again later down the line, you can type docker exec -it <docker_container_name> jupyter notebook list.
The docker run command is mandatory to open a port for the container to allow the connection from a host browser, assigning the port to the docker container with -p, select your jupyter image from your docker images.
docker run -it -p 8888:8888 image:version
Inside the container launch the notebook assigning the port you opened:
Access the notebook through your desktops browser on http://localhost:8888
The notebook will prompt you for a token which was generated when you create the notebook.
docker pull tensorflow/tensorflow # Download latest image
docker run -it -p 8888:8888 tensorflow/tensorflow # Start a Jupyter notebook server
You will receive a message like this:
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://127.0.0.1:8888/?token=d6e80acaf08e09853dc72f6b0f022b8225f94f
In the host, replace 127.0.0.1 with 192.168.99.100 and use the rest of that URL
As an alternative to building your own Docker image, you can also use the ML Workspace image. The ML Workspace is an open-source web IDE that combines Jupyter, VS Code, a Desktop GUI, and many other tools & libraries into one convenient Docker image. Deploying a single workspace instance is as simple as:
docker run -p 8080:8080 mltooling/ml-workspace:latest
All tools are accessible from the same port and integrated into the Jupyter UI. You can find further documentation here.
The Makefile below encapsulates the previous answers and ensures that jupyter and docker agree on the port. And if I just click/copy the link provided by jupyter, that solves port mismatch problems.
To use, just make jupyter or make jupyter PORT=xxxx from the proper folder. Then click the link in the jupyter output.
Remote Containers
If your container is on a remote host (say an AWS EC2), then you'll also need to set up an ssh tunnel with the correct port. For example, on the local machine:
But at least that's only one place I can manually mismatch ports.
Makefile
# Set your default jupyter port here.
# Avoid 8888 if you run local notebooks on that!
PORT=8888
# Your app root in the container.
APP_DIR=/app
# The docker image to launch. *** SET TO YOUR image:version! ***
APP_TAG=image:version
jupyter: ##
## Launch jupyter notebook from our container, mapping two folders
## Local Container Notes
## -----------------------------------------------------
## ./data -> /data Put data here!
## ./notebooks -> /notebooks Find notebooks here!
## -----------------------------------------------------
## Arg: PORT - specify port [${PORT}]
docker run \
-p $(PORT):$(PORT) \
-v $(PWD)/notebooks/:$(APP_DIR)/notebooks/ \
-v $(PWD)/data:/data \
$(APP_TAG) \
jupyter notebook --ip 0.0.0.0 --port $(PORT) \
--no-browser --allow-root