Day2- Set Up and Configure Jupyter Notebook Server
Requirements
A teammate has configured a JupyterLab server for the xFusionCorp Industries data science team, but the server does not behave correctly. Inspect the configuration, diagnose the issues, and start the server.
JupyterLab is already installed in the virtual environment at /root/code/ml-env/. The team's configuration file is at /root/code/jupyter_lab_config.py and is visible in the file explorer.
When JupyterLab is started, the Jupyter UI button at the top of the lab must open the notebook interface.
For this to work, the running server must meet the following requirements:
- it listens on port 8888;
- it binds on 0.0.0.0 (the lab proxy cannot reach a server that is only bound on 127.0.0.1);
- the notebook root directory is /root/notebooks/, and that directory exists on disk.
Open the configuration file, identify every setting that prevents the requirements above from being met, and correct it. Create any missing directories.
Start JupyterLab from the virtual environment using the corrected configuration:
source /root/code/ml-env/bin/activate
jupyter lab --config=/root/code/jupyter_lab_config.py --allow-root --no-browser &
Make sure JupyterLab is running before using the button at the top of the lab.
Note
This document focuses on the implementation approach. The task statement above is preserved as the original requirement source.
Prerequisites
- Access to the lab terminal with root privileges.
- The Python virtual environment already exists at:
/root/code/ml-env/
- The JupyterLab configuration file already exists at:
/root/code/jupyter_lab_config.py
- JupyterLab is already installed inside the provided virtual environment.
Steps
Inspect the Existing Configuration
Review the current JupyterLab configuration file:
cat /root/code/jupyter_lab_config.py
Identify incorrect values related to:
- IP binding
- Port configuration
- Notebook root directory
Edit the Configuration File
Open the configuration file:
vi /root/code/jupyter_lab_config.py
Update or add the following settings:
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.root_dir = '/root/notebooks/'
Ensure:
- The server binds to
0.0.0.0 - The listening port is
8888 - The notebook root directory is
/root/notebooks/
Create the Notebook Directory
Create the notebook root directory if it does not already exist:
mkdir -p /root/notebooks
Activate the Virtual Environment
Activate the provided Python virtual environment:
source /root/code/ml-env/bin/activate
Start JupyterLab
Start JupyterLab using the corrected configuration:
jupyter lab --config=/root/code/jupyter_lab_config.py --allow-root --no-browser &
Verification
Verify that JupyterLab is listening on port 8888:
ss -tulnp | grep 8888
Expected output should show:
- Port
8888 - Binding address
0.0.0.0
Example:
tcp LISTEN 0 128 0.0.0.0:8888
Verify the JupyterLab process is running:
ps -ef | grep jupyter
Finally:
- Use the Jupyter UI button at the top of the lab.
- Confirm the notebook interface opens successfully.
Resources
-
JupyterLab Documentation: [https://jupyterlab.readthedocs.io/]
-
Jupyter Server Configuration: [https://jupyter-server.readthedocs.io/en/latest/users/configuration.html]