SSH access to user notebook server

I would like to give users ssh access to their notebook servers. We are running jupyterhub in docker in the configuration in which the hub sits behind a traefik reverse-proxy, and user notebook servers are spawned using DockerSpawner.

I think I know what needs to be done at a conceptual level: traefik should forward a user specific port to the user container which should be listening on a specific port. I’m just not sure how the port allocation/discovery process would work.

Is there an example that is close to this, in which the spawner relates some information both to the reverse proxy and to the spawned container during the spawning process? I’m not averse to creating my own spawner class if necessary.

Thank you for any help or suggestions,



In case it helps anyone else, we were able to accomplish this using RobM’s answer to this SO question. The idea is to start a separate container that forwards network traffic to the user’s jupyter container. This separate container can be made accessible to the rest of the world as needed.