9

I have problems establishing a connection from my local machine to the jupyter notebook instance i have running on my remote server in a docker container.

What i did so far:

I connect to the remote server with ssh username@remoteHostIp

I run docker container ls to make sure my container is not already running

Now I start my container with docker run -it -p 8888:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning

Im now using the terminal in my container and start a browser-less jupyter notebook instance

jupyter notebook --no-browser --port=8889 --allow-root

It starts successfully:

The Jupyter Notebook is running at:
[I 11:14:51.979 NotebookApp] system]:8889/

Now i start another shell on my local computer and create a ssh tunnel:

ssh -N -f -L localhost:8888:localhost:8889 username@ remote_host_name

My shell returns the following after some seconds:

channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused

Iam unable to access the jupyter notebook with localhost:8888/ or localhost:8889/

When i run jupyter notebook on the remote server outside of the docker container and create the ssh tunnel everything works fine.

Some additional information: remote server: Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial

My local machine is running on osx moave

  • I also found this [this](https://stackoverflow.com/questions/37576193/create-ssh-tunnel-to-remote-docker-container-running-jupyter-notebook) thread but iam not really sure how this helps me with my problem, – QuestionableQuestions Feb 07 '19 at 11:44
  • 1
    Thanks for the answer, but the following command didn't work for me. `jupyter notebook --no-browser --port=8889 --allow-root`. Once ran with **--ip 0.0.0.0** it worked fine. `jupyter notebook --ip 0.0.0.0 --port=8889 --allow-root` – Shubham May 22 '20 at 07:51

2 Answers2

10

First you should connect to the remote server with

ssh username@remoteHostIp

After connecting to it you should run docker container using

docker run -it -p 8080:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning

i am considering here port 8888 is of jupyter notebook port and 8080 is of remote server port

Now Open a new terminal window on your local machine, SSH into the remote machine again using the following options to setup port forwarding.

ssh -N -L localhost:8000:localhost:8080 username@remoteHostIp

i am considering here port 8000 is of my local machine port and 8080 as i said above is of remote server port already

Now Access the remote jupyter server via your local browser. Open your browser and go to:

localhost:8000
  • But I dont see how he starts jupyter? There is no 'jupyter notebook' command anywhere. – aquagremlin Mar 30 '19 at 21:53
  • while running docker command the jupyter notebook will start, as we are connecting remote server port( 8080 ) to jupyter notebook port ( 8888 ) in that command – srilekha palepu - Intel Mar 31 '19 at 06:25
  • so, the container, waleedka/modern-deep-learning, has a command like './jupyter notebook' in a script that runs at startup of the container? Just because you open ports on the container to the host, jupyter does not have to automatically start. – aquagremlin Mar 31 '19 at 14:02
  • 1
    for this we need to keep run_jupyter.sh script file in Dockerfile like (CMD ["/run_jupyter.sh", "--allow-root"] ) before creating image. After creating the image, when we run container this will allows us to run jupyter notebook and also provided with token to connect – srilekha palepu - Intel Apr 01 '19 at 11:03
  • works for me - I don't see a `-f` option for `ssh` though --- what is that for? – mishaF Jun 17 '21 at 21:51
2

I solved the question myself by connecting to the remove server and checking for the docker container ip adress: docker inspect <container_name>. I used that ip adress then to create the ssh tunnel:

ssh -N -f -L localhost:8889:dockerContainerIpAdress:8889 username@ remote_host_name

now i am able to connect to the jupyter notebook in my local browser with localhost:8889