Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to jupyter notebook running in docker on a remote server

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

like image 863
QuestionableQuestions Avatar asked Feb 07 '19 11:02

QuestionableQuestions


People also ask

How do I run a Jupyter notebook from a docker container?

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. Inside the container launch the notebook assigning the port you opened:

How to run Jupyter Notebook on a remote server?

When we run some large datasets, it is often to run them on a powerful remote server, and a common scenario is to run and access Jupyter Notebook remotely. Let’s see the setup process and tips to keep it running upon SSH terminal disconnection. 1. Login to Remote Server Just a normal SSH login. Replace with your username and server address. 2.

How to SSH into Jupyter notebook from another server?

Just a normal SSH login. Replace with your username and server address. 2. Run Notebook with Specified Port Number. Once logged in to the remote server, cd to the desired directory, and run the following command: jupyter notebook --no-browser --port=8086. It will start the Jupyter Notebook on the specified port number.

How do I set up port forwarding for Jupyter Notebook?

Jupyter Notebook runs on a certain port on the machine. Hence, the basic idea would be to make that port reachable from your host machine. Luckily, ssh provides the -L option to specify port forwarding. In my case I use port 9999 in both ends, namely <host port> = <remote port> = 9999. Here the approach is exactly the same as before.


2 Answers

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
like image 87
srilekha palepu - Intel Avatar answered Sep 28 '22 08:09

srilekha palepu - Intel


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

like image 20
QuestionableQuestions Avatar answered Sep 28 '22 09:09

QuestionableQuestions