-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Use environment variable to set port to run on #5212
Comments
No, this CLI option is not currently tied to an environment variable. I believe the preference in notebook is to avoid that where possible (although containerized envs make this approach attractive). |
@kevin-bates yep you said it - it would be useful for working with containers. thanks for the info |
Hi @json2d . I'm inclined to propose we identify a small set of container-relevant options and env variable associations to them. The previously mentioned preference may have been more of a "generally speaking" thing, and I think there could be value here. I think I'm going to re-open this until we determine the best approach forward here. Thanks. |
At the moment there are a few steps involved in running Jupyter containers with the port set via an environment variable like First you need to create a FROM jupyter/minimal-notebook:latest
ENV NB_PORT 8888
# run notebook on 0.0.0.0:8888
CMD jupyter notebook --port=$NB_PORT --no-browser Second you need to build and tag the image:
Finally you can run the image with $ export NB_PORT=9999
$ docker run --env NB_PORT -p $NB_PORT:$NB_PORT json2d/jupyter It gets a bit messy when you go to publish/expose the port, but that's just what you have to do with Docker. So if Jupyter could be patched to automatically use an environment like $ export NB_PORT=9999
$ docker run --env NB_PORT -p $NB_PORT:$NB_PORT jupyter/minimal-notebook:latest |
Thanks @json2d. Your example reminds me about the docker-stacks images and how this could be accomplished via the various start scripts. However, there are many who might build their own images and would like this capability. I think by adding support for specifying port via an env wihtin the application, we can allow for the existing behaviors to override. For example, the default port number would essentially come from the env, but the CLI option export JUPYTER_PORT=8899
jupyter notebook --port 9999 Notebook would start on port export JUPYTER_PORT=8899
jupyter notebook it would start on port Because its imperative that port-retries be zero in these circumstances, yet its current default is I can try to put together a pull request for this if you agree. Once a PR is present, I think others might find a need to comment. |
I think having the CLI option |
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 jupyter#5212
@json2d - I submitted the PR above. It would be great if you could take it for a spin in your env to see how things work out. |
* 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
So i get this is how you would set the port via cli:
Is there currently a way to set this and other run options with an environment variable eg:
The text was updated successfully, but these errors were encountered: