Deployment Overview of Jupyter Notebook on Server¶
Prerequisites and Basic Requirements¶
The application requires a server running Ubuntu to ensure compatibility with the installation scripts. The following system requirements and configurations must be met:
-
Operating System: Ubuntu
-
Privileges: Root or sudo access is required for package installation and service management.
-
Ports:
-
443(External HTTPS access) -
8888(Internal application port)
FQDN of the final panel on the hostkey.in domain¶
The application is accessible via a specific subdomain template based on the server ID.
| Parameter | Value |
|---|---|
| Prefix | notebook |
| Domain | hostkey.in |
| Full template | notebook{Server_ID_from_Invapi}.hostkey.in |
File and Directory Structure¶
The deployment utilizes several specific directories for data, configuration, and proxy management:
-
/opt/data: Main application data directory. -
/opt/data/jupyter: Python virtual environment and Jupyter workspace. -
/root/.jupyter/: Jupyter configuration files. -
/root/nginx/: Nginx reverse proxy configuration and Docker Compose files. -
/data/nginx/user_conf.d/: Custom Nginx user configurations. -
/data/nginx/nginx-certbot.env: Environment variables for the Nginx container.
Application installation process¶
The installation follows a multi-step process involving system package management and Python environment setup:
-
System Dependencies: The system is updated, and essential packages are installed via
apt, includingpython3,python3-pip,jupyter, andpython3-virtualenv. -
User Setup: A dedicated system user named
jupyter(UID2841) is created to run the application processes securely. -
Virtual Environment Creation: A Python virtual environment is initialized at
/opt/data/jupyterunder thejupyteruser. -
Python Package Installation: The following packages are installed within the virtual environment:
-
notebook -
voila -
virtualenv -
jupyter-server -
Configuration Generation:
-
A Jupyter configuration file is generated.
-
Security settings are applied to allow cross-origin requests (
c.ServerApp.allow_origin = '*'). -
An authentication password is automatically generated and configured for the server.
-
Service Configuration: A systemd service unit is created at
/usr/lib/systemd/system/jupyter-notebook.serviceto manage the application lifecycle.
Access Rights and Security¶
-
User Isolation: The core application runs under the
jupyteruser, while the reverse proxy handles external traffic. -
Firewall: External access is restricted to port
443. -
Authentication: Access to the Jupyter interface is protected by a password generated during installation.
Docker Containers and Their Deployment¶
The deployment utilizes a Docker container to manage SSL certificates and Nginx reverse proxying via Docker Compose.
Nginx Proxy Container
-
Image:
jonasal/nginx-certbot:latest -
Ports: Uses
hostnetwork mode to bind directly to host ports. -
Volumes:
-
nginx_secrets:/etc/letsencrypt: Shared volume for SSL certificates. -
/data/nginx/user_conf.d:/etc/nginx/user_conf.d: Custom Nginx configuration files. -
/home:/home: Access to host home directories. -
Environment Variables:
-
[email protected](Configured via.envfile). -
Restart Policy:
unless-stopped
Custom Scripts and Additional Setup¶
The deployment performs several automated configuration steps:
-
Password Generation: An automated process executes
/opt/data/jupyter/bin/jupyter notebook passwordto secure the instance. -
Service Initialization: The systemd service is configured to start automatically on boot, pointing to the specific virtual environment and working directory (
/opt/data).
Application Update Instructions¶
To update the main Jupyter Notebook application, follow these steps:
-
Ensure the Python virtual environment is active or use the absolute path to the pip binary.
-
Upgrade the core packages using
pip:
Location of configuration files and data¶
| Component | Path |
|---|---|
| Jupyter Configuration | /root/.jupyter/jupyter_notebook_config.py |
| Application Data | /opt/data/jupyter/share/jupyter |
| Nginx Configs | /data/nginx/user_conf.d/ |
Available ports for connection¶
-
HTTPS (External):
443 -
Jupyter Internal:
8888
Starting and Stopping the application¶
The application is managed via systemd.
Start the application:
Stop the application:
Check status:
Proxy Servers¶
The deployment uses an Nginx container managed by nginx-certbot. This setup handles SSL termination via Let's Encrypt and provides a secure HTTPS entry point for the Jupyter Notebook instance. The configuration is driven by files located in /data/nginx/user_conf.d/ and environment variables defined in /data/nginx/nginx-certbot.env.