Skip to content

Commit

Permalink
Merge pull request #1619 from romainx/feat-1217-1
Browse files Browse the repository at this point in the history
Switch the default to Jupyter Server configuration file
  • Loading branch information
mathbunnyru committed Feb 12, 2022
2 parents 48a41e5 + 33331bb commit 1ef8838
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
8 changes: 4 additions & 4 deletions base-notebook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ CMD ["start-notebook.sh"]
# Copy local files as late as possible to avoid cache busting
COPY start.sh start-notebook.sh start-singleuser.sh /usr/local/bin/
# Currently need to have both jupyter_notebook_config and jupyter_server_config to support classic and lab
COPY jupyter_notebook_config.py /etc/jupyter/
COPY jupyter_server_config.py /etc/jupyter/

# Fix permissions on /etc/jupyter as root
USER root

# Prepare upgrade to JupyterLab V3.0 #1205
RUN sed -re "s/c.NotebookApp/c.ServerApp/g" \
/etc/jupyter/jupyter_notebook_config.py > /etc/jupyter/jupyter_server_config.py && \
# Legacy for Jupyter Notebook Server, see: [#1205](https://github.com/jupyter/docker-stacks/issues/1205)
RUN sed -re "s/c.ServerApp/c.NotebookApp/g" \
/etc/jupyter/jupyter_server_config.py > /etc/jupyter/jupyter_notebook_config.py && \
fix-permissions /etc/jupyter/

# Switch back to jovyan to avoid accidental container runs as root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


c = get_config() # noqa: F821
c.NotebookApp.ip = "0.0.0.0"
c.NotebookApp.port = 8888
c.NotebookApp.open_browser = False
c.ServerApp.ip = "0.0.0.0"
c.ServerApp.port = 8888
c.ServerApp.open_browser = False

# https://github.com/jupyter/notebook/issues/3130
c.FileContentsManager.delete_to_trash = False
Expand Down Expand Up @@ -49,7 +49,7 @@
)
# Restrict access to the file
os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
c.NotebookApp.certfile = pem_file
c.ServerApp.certfile = pem_file

# Change default umask for all subprocesses of the notebook server if set in
# the environment
Expand Down
13 changes: 8 additions & 5 deletions docs/using/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This page describes the options supported by the startup script and how to bypas

## Jupyter Server Options

You can pass [Jupyter server options](https://jupyter-notebook.readthedocs.io/en/stable/public_server.html) to the `start-notebook.sh` script when launching the container.
You can pass [Jupyter server options](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html) to the `start-notebook.sh` script when launching the container.

1. For example, to secure the Notebook server with a custom password hashed using `IPython.lib.passwd()` instead of the default token,
you can run the following (this hash was generated for `my-password` password):
Expand All @@ -18,7 +18,7 @@ You can pass [Jupyter server options](https://jupyter-notebook.readthedocs.io/en
start-notebook.sh --NotebookApp.password='sha1:7cca89c48283:e3c1f9fbc06d1d2aa59555dfd5beed925e30dd2c'
```

2. To set the [base URL](https://jupyter-notebook.readthedocs.io/en/stable/public_server.html#running-the-notebook-with-a-customized-url-prefix) of the notebook server, you can run the following:
2. To set the [base URL](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#running-the-notebook-with-a-customized-url-prefix) of the notebook server, you can run the following:

```bash
docker run -it --rm -p 8888:8888 jupyter/base-notebook \
Expand Down Expand Up @@ -165,10 +165,13 @@ The certificate file or PEM may contain one or more certificates (e.g., server,

For additional information about using SSL, see the following:

- The [docker-stacks/examples](https://github.com/jupyter/docker-stacks/tree/master/examples) for information about how to use
- The [docker-stacks/examples](https://github.com/jupyter/docker-stacks/tree/master/examples)
for information about how to use
[Let's Encrypt](https://letsencrypt.org/) certificates when you run these stacks on a publicly visible domain.
- The [jupyter_notebook_config.py](https://github.com/jupyter/docker-stacks/blob/master/base-notebook/jupyter_notebook_config.py) file for how this Docker image generates a self-signed certificate.
- The [Jupyter Notebook documentation](https://jupyter-notebook.readthedocs.io/en/latest/public_server.html#securing-a-notebook-server) for best practices about securing a public notebook server in general.
- The [`jupyter_server_config.py`](https://github.com/jupyter/docker-stacks/blob/master/base-notebook/jupyter_server_config.py)
file for how this Docker image generates a self-signed certificate.
- The [Jupyter Server documentation](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html#securing-a-jupyter-server)
for best practices about securing a public notebook server in general.

## Alternative Commands

Expand Down
6 changes: 3 additions & 3 deletions examples/openshift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ If you want to set any custom configuration for the notebook, you can edit the c
oc edit configmap/mynotebook-cfg
```

The `data` field of the config map contains Python code used as the `jupyter_notebook_config.py` file.
The `data` field of the config map contains Python code used as the `jupyter_server_config.py` file.

If you are using a persistent volume, you can also create a configuration file at:

```lang-none
/home/jovyan/.jupyter/jupyter_notebook_config.py
/home/jovyan/.jupyter/jupyter_server_config.py
```

This will be merged at the end of the configuration from the config map.
Expand Down Expand Up @@ -209,7 +209,7 @@ oc set env dc/mynotebook JUPYTER_NOTEBOOK_PASSWORD=mypassword

This will trigger a new deployment so ensure you have downloaded any work if not using a persistent volume.

If using a persistent volume, you could instead setup a password in the file `/home/jovyan/.jupyter/jupyter_notebook_config.py` as per guidelines in <https://jupyter-notebook.readthedocs.io/en/stable/public_server.html>.
If using a persistent volume, you could instead setup a password in the file `/home/jovyan/.jupyter/jupyter_server_config.py` as per guidelines in <https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html>.

## Deploying from a Custom Image

Expand Down
4 changes: 2 additions & 2 deletions examples/openshift/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"data": {
"jupyter_notebook_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_notebook_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
}
},
{
Expand Down Expand Up @@ -81,7 +81,7 @@
"image": "${NOTEBOOK_IMAGE}",
"command": [
"start-notebook.sh",
"--config=/etc/jupyter/openshift/jupyter_notebook_config.py",
"--config=/etc/jupyter/openshift/jupyter_server_config.py",
"--no-browser",
"--ip=0.0.0.0"
],
Expand Down
4 changes: 2 additions & 2 deletions examples/source-to-image/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
}
},
"data": {
"jupyter_notebook_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_notebook_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
"jupyter_server_config.py": "import os\n\npassword = os.environ.get('JUPYTER_NOTEBOOK_PASSWORD')\n\nif password:\n import notebook.auth\n c.NotebookApp.password = notebook.auth.passwd(password)\n del password\n del os.environ['JUPYTER_NOTEBOOK_PASSWORD']\n\nimage_config_file = '/home/jovyan/.jupyter/jupyter_server_config.py'\n\nif os.path.exists(image_config_file):\n with open(image_config_file) as fp:\n exec(compile(fp.read(), image_config_file, 'exec'), globals())\n"
}
},
{
Expand Down Expand Up @@ -275,7 +275,7 @@
"image": "${APPLICATION_NAME}:latest",
"command": [
"start-notebook.sh",
"--config=/etc/jupyter/openshift/jupyter_notebook_config.py",
"--config=/etc/jupyter/openshift/jupyter_server_config.py",
"--no-browser",
"--ip=0.0.0.0"
],
Expand Down

0 comments on commit 1ef8838

Please sign in to comment.