defeo / jupyterhub-docker

A configuration for a JupyterHub+DockerSpawner+CASAuthenticator server with Traefik proxy, based on docker-compose
https://opendreamkit.org/2018/10/17/jupyterhub-docker/
MIT License
202 stars 112 forks source link

Blocking Networking not working #18

Open Melhaya opened 2 years ago

Melhaya commented 2 years ago

Hello,

Thank you so much for this repository. It is the perfect middle ground for the current JupyterHub deployments out there.

In my setup, I managed to set up JupyterHub on my server and it is accessed without any issues. However, I have an issue. I am trying to block users from accessing the host's network.

This is the current docker-compose file:

version: "3"

services:
  jupyterhub:
    restart: always
    build: ./jupyterhub
    hostname: jupyterhub
    ports:
      - "8080:8000"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      DOCKER_NOTEBOOK_IMAGE: "exam-scipy-notebook"
      DOCKER_NETWORK_NAME: "jupyterhub-network"
      DOCKER_JUPYTER_IMAGE: "jupyterhub/singleuser:latest"
      HUB_IP: "jupyterhub"
      LTI_CLIENT_KEY: "${LTI_CLIENT_KEY}"
      LTI_SHARED_SECRET: "${LTI_SHARED_SECRET}"

networks:
  default:
    external:
      name: "jupyterhub-network"

I am not sure what I need to edit to remove the communication between the docker containers created and the host network.

Your help would be highly appreciated.

This is the networking part in the config.py file:

from dockerspawner import DockerSpawner 

# Spawn single-user servers as Docker containers
c.JupyterHub.spawner_class = DockerSpawner
c.DockerSpawner.remove_containers = True

# Spawn containers from this image
c.DockerSpawner.image = os.environ['DOCKER_NOTEBOOK_IMAGE']

# Connect containers to this Docker network
network_name = os.environ['DOCKER_NETWORK_NAME']
c.DockerSpawner.use_internal_ip = True
c.DockerSpawner.network_name = network_name
# Pass the network name as argument to spawned containers
c.DockerSpawner.extra_host_config = { 'network_mode': network_name }

# Remove containers once they are stopped
c.DockerSpawner.remove_containers = True
# For debugging arguments passed to spawned containers
c.DockerSpawner.debug = True

# User containers will access hub by container name on the Docker network
c.JupyterHub.hub_ip = os.environ['HUB_IP']
c.JupyterHub.hub_port = 8080