Here's a simple setup to deploy JupyterHub locally using Docker. This setup will use the jupyterhub/jupyterhub
Docker image, which provides a basic JupyterHub installation.
This Dockerfile
will create an environment with JupyterHub:
FROM jupyterhub/jupyterhub
# No additional setup needed for the simplest case
# JupyterHub will run with default configurations
CMD ["jupyterhub"]
For JupyterHub to run, you need a configuration file. Here's a very basic one:
# jupyterhub_config.py
c.JupyterHub.spawner_class = 'simple'
c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'
c.DummyAuthenticator.password = "password" # Set a simple password for all users
c.Authenticator.admin_users = {'admin'} # Set 'admin' as an admin user
This configuration tells JupyterHub to use a simple spawner, which starts single-user notebook servers directly without any sophisticated user management or authentication for simplicity.
Before running the Docker container, generate a random encryption key for JupyterHub:
openssl rand -hex 32
Save this key, as you'll need it in the next step.
-
Build the Docker image:
docker build -t my-jupyterhub .
-
Run the Docker container:
docker run -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/srv/jupyterhub -e JUPYTERHUB_CRYPT_KEY=<your-generated-key> my-jupyterhub
Here's what each part does:
-p 8000:8000
: Maps port 8000 from the container to your local machine.-v /var/run/docker.sock:/var/run/docker.sock
: Allows JupyterHub to spawn new Docker containers for users.-v $(pwd):/srv/jupyterhub
: Mounts the current directory to/srv/jupyterhub
in the container, where JupyterHub looks for its config file.-e JUPYTERHUB_CRYPT_KEY=<your-generated-key>
: Sets the encryption key for JupyterHub. Replace<your-generated-key>
with the key you generated in Step 3.
-
Open a web browser and navigate to
http://localhost:8000
. You'll be greeted by JupyterHub's login page. Since we didn't set up any authentication, you can enter any username and password to log in. -
After logging in, you'll be able to start a new notebook server, which will run in a separate Docker container.
-
Security: This setup is for testing purposes only. In a production environment, you'd need proper authentication, SSL for secure connections, and possibly integration with existing user systems or OAuth.
-
Persistence: Notebooks created in this setup are stored inside the user's Docker container. If you want persistence across container restarts, you'll need to configure volume mounts for user data.
-
Scalability: This simple setup doesn't scale well for many users. For more users or production use, consider using Kubernetes with Helm charts for JupyterHub, known as Zero to JupyterHub.
This setup provides the quickest way to get a functional JupyterHub instance running locally for testing or small-scale use. Remember, for any real-world application, you'd need to expand on security, user management, and resource allocation.