Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display hostname when running remotely #3356

Merged
merged 2 commits into from Feb 27, 2018

Conversation

Projects
None yet
4 participants
@evandam
Copy link
Contributor

evandam commented Feb 21, 2018

My team often runs Jupyter notebooks on a remote server, but 'localhost' is always displayed when running with an option like --ip '*' or --ip 0.0.0.0, meaning the link isn't copy-and-pasteable when trying to connect from another machine.

This change checks if you are running locally (either the current hostname, localhost, or 127.0.0.1) and displays localhost as expected, but otherwise provides the server name.

Hopefully this is the right way to go about proposing a change!

@minrk minrk merged commit b66a60d into jupyter:master Feb 27, 2018

4 checks passed

codecov/patch 75% of diff hit (target 0%)
Details
codecov/project 77.92% (-0.01%) compared to 25c628c
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@minrk

This comment has been minimized.

Copy link
Member

minrk commented Feb 27, 2018

This is a solid improvement, thanks!

@takluyver takluyver added this to the 5.5 milestone Apr 24, 2018

@cyberwillis

This comment has been minimized.

Copy link

cyberwillis commented May 3, 2018

Any chance to make this optional in command line ?

like this:

--no-translate-hostname

Here I use LXC container and by this change I have to edit my /etc/hosts everytime a new container is instantiated. LXC doesn't make easy to bind locahost ports between Host and Container, like docker does. I still looking to some other ways to make a workaround in LXC.

For now I am holding the notebook==5.4.1 to not get stuck

@evandam

This comment has been minimized.

Copy link
Contributor Author

evandam commented May 4, 2018

I'm happy to give this a shot if it makes sense to do so. Maybe even something like --display-name localhost where you can explicitly set how the URL will be formed?

However, this is really just a convenience change. It really shouldn't cause any functional difference, unless I'm not understanding how your configuration works?

@cyberwillis

This comment has been minimized.

Copy link

cyberwillis commented May 4, 2018

Hi...
Sure I can try to explain...

When I build a container for LXC it reserves a IP for the container and also register the specific IP number into a alias inside the container so I can call it easly.

The alias has this pattern:

export JUPYTER_IP=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
alias jlab='jupyter lab --port=$JUPYTER_PORT --ip=$JUPYTER_IP --no-browser --NotebookApp.password='sha1:$JUPYTER_SECRET' --NotebookApp.notebook_dir=/projects --allow-root'

Until notebook==5.4.1, the access by the IP address was ok.
Just to mention tough, in case I had omitted the "--ip" on alias, the nootbook would show up with an address like that http://locahost:8888 or http://0.0.0.0:8888, that could not access at all because "localhost" cannot be binded between host and container in LXC. In docker it can, or at least does not exist a easy way to do so on LXD / LXC. There are many threads about this issue on the internet and I could not find any viable solution.

When notebook==5.5.0rc1 showed up, translating ip into domain names / machine names, every time notebook become online i get this address http://container:8888/ that I cannot access by name unless I start to managing it into my /etc/hosts or remembering the original IP number from before.

What do you propose ?

@cyberwillis

This comment has been minimized.

Copy link

cyberwillis commented May 4, 2018

I just found that the new version of LXD 3.0 released abril 2, supports the binding by creating a proxy for that. I will setup to see.

If its true will be possible bind to my HOST by localhost and port.

@cyberwillis

This comment has been minimized.

Copy link

cyberwillis commented May 4, 2018

Hi again,
I could confirm it.

Now I can bind to my HOST localhost on LXD 3.0 so independent of been Hostname or IP I can use localhost now.

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented May 4, 2018

So the issue is/was that a container had a different host name internally and externally, so it was showing a name that wasn't useful externally? Maybe instead of special casing localhost and 127.0.0.1 in one direction, it would be more robust to special case * and 0.0.0.0 in the other direction? I.e. look up the hostname in those cases and use self.ip otherwise.

@cyberwillis I'm a bit confused by your last message; is this still a problem for you, or is it OK for you with the new version of LXD? Thanks for testing the RC!

@cyberwillis

This comment has been minimized.

Copy link

cyberwillis commented May 4, 2018

Hi, again

It becames a problem when the new rc1 started to translate from IP to machine name, because I would have to manage of DNS internal on my host to translate it back.

Anyway my problem was solved. I just ripped off the --ip argument and started to use the new version of my container runtime that can forward IPs and Ports for my localhost.

But what I was tryied to explain earllier is that, is preferable to inform an IP like 192.168.1.30 and be accessible by it instead of translating into names. That's why I sugested a parameter that could let me choose if I need or not translation of the IP into machine name.

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented May 4, 2018

Right, and we can add an option for it if we have to, but that's only helpful for people who've figured out what's gone wrong and discovered the option. If this is going to be a problem for a lot of people, I'd like to understand what's going on now and work out if we can make it work for more people without requiring them to set an option.

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented May 4, 2018

So I've just tried it locally, and I think maybe it's more robust to change this logic:

# What we have now:
if self.ip in ('localhost', '127.0.0.1', hostname):
    ip = self.ip
else:
    ip = hostname

To something like this:

# Proposed
if self.ip in ('', '0.0.0.0'):
    ip = hostname
else:
    ip = self.ip

I.e. prefer the IP address where a meaningful one was specified, since that's potentially more likely to work from other machines, but use the hostname when we don't have a meaningful IP address, which is @evandam's use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.