Skip to content

Commit

Permalink
Add env variable support for port options (#5221)
Browse files Browse the repository at this point in the history
* Add env variable support for port options

In order to better support use cases relating to containerized environments,
this change adds environment variable support for the `--port` option.  Since
anyone setting a specific port probably doesn't want port retry logic enabled,
the `--port-retries` option has also been backed by an env.

Option `--port` will be backed by env `JUPYTER_PORT` and still defaults to `8888`.
Option `--port-retries` will be backed by env `JUPYTER_PORT_RETRIES` and still
defaults to `50`.

The CLI options will override those set via the envrionment, but environment
values override those set via configuration files.

Closes #5212

* Fixup after merge
  • Loading branch information
kevin-bates authored May 16, 2020
1 parent cbfc4da commit d2d50f1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,28 @@ def _validate_ip(self, proposal):
or containerized setups for example).""")
)

port = Integer(DEFAULT_NOTEBOOK_PORT, config=True,
help=_("The port the notebook server will listen on.")
port_env = 'JUPYTER_PORT'
port_default_value = DEFAULT_NOTEBOOK_PORT
port = Integer(port_default_value, config=True,
help=_("The port the notebook server will listen on (env: JUPYTER_PORT).")
)

@default('port')
def port_default(self):
return int(os.getenv(self.port_env, self.port_default_value))

port_retries_env = 'JUPYTER_PORT_RETRIES'
port_retries_default_value = 50
port_retries = Integer(port_retries_default_value, config=True,
help=_("The number of additional ports to try if the specified port is not "
"available (env: JUPYTER_PORT_RETRIES).")
)

@default('port_retries')
def port_retries_default(self):
return int(os.getenv(self.port_retries_env, self.port_retries_default_value))


sock = Unicode(u'', config=True,
help=_("The UNIX socket the notebook server will listen on.")
)
Expand Down Expand Up @@ -823,9 +841,6 @@ def _validate_sock_mode(self, proposal):
)
return value

port_retries = Integer(50, config=True,
help=_("The number of additional ports to try if the specified port is not available.")
)

certfile = Unicode(u'', config=True,
help=_("""The full path to an SSL/TLS certificate file.""")
Expand Down

2 comments on commit d2d50f1

@meeseeksmachine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/change-port-from-8888-to-say-7777-in-jupyterlab-dockerfile/3621/4

@antofthy
Copy link

@antofthy antofthy commented on d2d50f1 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also need to disable to update the Dockerfile "HEALTHCHECK"
or you will finds the container dying after around 46 seconds of run time!

jupyter/docker-stacks#1817

That environment variable is also overridden by a hardcoded port value in the config files /etc/jupyter/ within the Dockerfiles.

Please sign in to comment.