7
votes

I want to run jupyter notebook running on my ubuntu vm which i fired using vagrant.

$ jupyter notebook --no-browser --port 8004
[I 18:26:10.152 NotebookApp] Serving notebooks from local directory: /home/vagrant/path/to/jupyter/notebook/directory
[I 18:26:10.153 NotebookApp] 0 active kernels
[I 18:26:10.154 NotebookApp] The Jupyter Notebook is running at: http://localhost:8004/
[I 18:26:10.154 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Jupyter notebook starts in localhost. But to access the notebook from my host machine I need to start the notebook in 0.0.0.0. How to bind the ip 0.0.0.0 so that it routes to 127.0.0.1 in the vm?

My host machine is windows and vm is ubuntu 14.04.4

4
Virtualbox has a port forwarding window...OneCricketeer
Alternatively, Docker has a Jupyter image if that is all you are using Vagrant forOneCricketeer

4 Answers

13
votes

Running a notebook server gives the answer

First generate jupyter_notebook_config.py file

$ jupyter notebook --generate-config

By default jupyter_notebook_config.py would have everything commented. Modify the following entries:

  • Accept incoming request from any host (not only localhost)
    Find #c.NotebookApp.ip = 'localhost' and change it to c.NotebookApp.ip = '*'
  • Do not launch a browser
    Find #c.NotebookApp.open_browser = True and change it to c.NotebookApp.open_browser = False
3
votes

As a comment above states, you need to forward the port on your VM.

When you run a VM the network on the box generally has little/no access to the outside world unless you grant it. Normally you'll be able to make a connection from the VM to the outside, but to listen on ports is another step.

Let's say your hostname is myhostname, when you put myhostname:8080 in the browser it will get rejected as your box doesn't have anything running. Now let's say your VM is running a server on 8080 and you want to link the two. You need to follow the instructions below so that when you hit myhostname:8080 your native OS will see that the VM is listening to that port. The request will get passed to the VM which will then in turn forward it to your jupyter instance.

These are the best instructions I found:

https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/

Here are some screenshots of my setup. I ran 'python -m http.server 8000' to have a server to connect to.

Set up your VM like this: VM setup

Connect from your native OS to the virtual server like this: Hitting the server from your native OS

Other users on your domain should be able to connect via :8000. You can get that on windows by typing 'hostname' on the command line.

Let's say you want to expose your http server to other users on port 80, but still run on port 8000 from within your server, you simply change the portforwarding config int he screenshot so that Host Port is 80, rather than 8000.

Hope this helps

2
votes

You may use --ip argument to change The IP address the notebook server will listen on.

Run:

jupyter notebook --ip=0.0.0.0

Note: Run jupyter notebook --help to check arguments.

--ip=<Unicode> (NotebookApp.ip)
    Default: 'localhost'
    The IP address the notebook server will listen on.
0
votes

Looks like that in newer versions of Jupyter the changes that should be done in the configuration is a little different from the above answers (otherwise you can get error "'' does not appear to be an IPv4 or IPv6 address").

The entire solution:

Run:

  • jupyter notebook --generate-config

Change in the config the bellow:

  • c.NotebookApp.ip = '0.0.0.0'
  • c.NotebookApp.open_browser = False

Now you can run Jupyter simply:

  • jupyter notebook