SwarmSpawner pass along uid and gid in single-user server

Hi Everyone,

I want to add a direct access image for our containerized jupyterhub to have the same experience as direct access on a host installed jupyterhub, only difference that our direct access is a container. I can run it outside of jupyterhub with this command: sudo docker run --rm -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -v $HOME:/home/student -it ubuntu_conda:test bash

Mounting the volume seems to work but not passing along the uid and gid, I have also tried to declare them statically during troubleshooting but no luck so far. Here is my(somewhat messy) jupyterhub_config.py:

c.ConfigurableHTTPProxy.should_start = False

c.ConfigurableHTTPProxy.api_url = ‘http://proxy:8001’

# tell the hub to use Dummy Auth (for testing)

c.JupyterHub.authenticator_class = ‘dummy’

# use SwarmSpawner

c.JupyterHub.spawner_class = ‘dockerspawner.SwarmSpawner’

# The Hub should listen on all interfaces,

# so user servers can connect

c.JupyterHub.hub_ip = ‘0.0.0.0’

# this is the name of the ‘service’ in docker-compose.yml

c.JupyterHub.hub_connect_ip = ‘hub’

# this is the network name for jupyterhub in docker-compose.yml

# with a leading ‘swarm_’ that docker-compose adds

c.SwarmSpawner.network_name = ‘swarm_jupyterhub-net’

# increase launch timeout because initial image pulls can take a while

c.SwarmSpawner.spawn_timeout = 100

c.SwarmSpawner.http_timeout = 100

# start jupyterlab

c.Spawner.cmd = [“jupyter”, “labhub”]

# debug-logging for testing

import logging

c.JupyterHub.log_level = logging.DEBUG

### NON DEFAULT ###

#c.Spawner.image = ‘euclid_nvidiatorch:latest’

username = ‘lageber’

uid = 1117

gid = 1117

c.SwarmSpawner.extra_container_spec = {

‘user’: ‘1117’

}

c.SwarmSpawner.environment = {

‘JUPYTER_ENABLE_LAB’: ‘yes’,

‘NB_USER’: f’{username}',

‘USER_ID’: int(uid),

‘GROUP_ID’: int(gid),

}

#c.SwarmSpawner.extra_container_spec = {

# “env”: [“USER_ID=$(id -u)”, “GROUP_ID=$(id -g)”]

#}

c.SwarmSpawner.volumes = { ‘/home/{username}’: ‘/home/student’}

c.SwarmSpawner.image = ‘ubuntu_conda:latest’

Try using the official Jupyter docker-stacks images, they’ve got support for setting the user-id, group-id, and username

2 Likes

Thank you very much for showing this! Had completely missed it and seems to do what we need.

2 Likes