Connect to remote jupyter notebook inside docker container
Target Use Case
Connect to a jupyter notebook server within a remote docker, and open it in your local browser or VS Code.
Docker (running notebook) → Host → Mac/PC (Running VS Code/browser)
Step 1: Connect from docker to host
- docker side: expose a port (tell docker you want to use this port),and publish it (actually open up the port and map to the port on the host)
- Notice that you can only expose a port before running the container
# port mapping format HOST:CONTAINER
docker run --expose=8888 -p 8888:8888
- Jupyter notebook: launch the notebook
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root path_to_notebook
Step 2: Connect host to your local client (VS Code or web browser)
- Open up the port 8888 on your host machine
- You can follow the instruction here. If you are using cloud-based server, remember to update security group rules by allowing incoming traffic through
8888
- You can follow the instruction here. If you are using cloud-based server, remember to update security group rules by allowing incoming traffic through
- After the notebook has started, it will give you a link that looks like:
http://127.0.0.1:8888/tree?token=xxxxxxxxxxxxxxxx
then,
- Web browser: copy the link, replace
127.0.0.1
with the host server address and paste in browser - VS Code: Seems to work only on vscode.dev: https://code.visualstudio.com/docs/datascience/notebooks-web#_connect-to-a-remote-jupyter-server