How to configure the NB_UID using DockerSpawner with jupyterhub-singleuser image

1,628 views
Skip to first unread message

Maria Julia Lima

unread,
Aug 29, 2017, 9:49:47 AM8/29/17
to Project Jupyter
Hi

Is it possible to set the NB_UID used by the container (rather than 1000, that is currently used by default)?

Thanks
--Julia

MinRK

unread,
Aug 31, 2017, 10:34:09 AM8/31/17
to Project Jupyter

There are two primary ways to set the uid of the containers:

  1. you can set the user-id of the container at the docker level with extra_create_kwargs['user'] = '1234:100'
  2. you can set the NB_UID environment variable and run the container as root

And there are two ways to set these values: for all users and different for each user. To do it for all users, you can do it all via config. For per-user classes, you will. need to define a small subclass of DockerSpawner to add your logic.

Some sample snippets of jupyterhub_config.py for each of the four cases:

all containers run as the same non-default uid:

c.DockerSpawner.extra_create_kwargs = {'user' : '1234:users'}

All containers start as root and set the same uid, via docker-stacks NB_UID env:

c.DockerSpawner.extra_create_kwargs = {'user' : '0'}
c.DockerSpawner.environment = {'NB_UID' : '1234'}

Set user at docker-level, different for each user

from dockerspawner import DockerSpawner

class MyDockerSpawner(DockerSpawner):
    def uid_for_user(self, user):
        # you implement me
        return '1234'

    def start(self):
        self.extra_create_kwargs['user'] = self.uid_for_user(self.user)
        return super().start()

c.JupyterHub.spawner_class = MyDockerSpawner

All containers start as root and set unique uids, via docker-stacks NB_UID env:

from dockerspawner import DockerSpawner

class MyDockerSpawner(DockerSpawner):
    def uid_for_user(self, user):
        # you implement me
        return '1234'

    def get_env(self):
        env = super().get_env()
        env['NB_UID'] = self.uid_for_user(self.user)
        return env

c.DockerSpawner.extra_create_kwargs = {'user' : '0'}
c.JupyterHub.spawner_class = MyDockerSpawner

Hopefully one of those is helpful!

-Min


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/9446f8ae-4a4b-422d-abcd-556fbdacec3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bernhard....@gmail.com

unread,
May 6, 2019, 4:08:28 AM5/6/19
to Project Jupyter
Thanks for this detailed description.


Am Donnerstag, 31. August 2017 16:34:09 UTC+2 schrieb Min RK:

There are two primary ways to set the uid of the containers:

  1. you can set the user-id of the container at the docker level with extra_create_kwargs['user'] = '1234:100'
  2. you can set the NB_UID environment variable and run the container as root

For me solution 3 does not work, because I can not change the user id if the container is not running as root.
I get a 'Permission Denied' message. 

 
Reply all
Reply to author
Forward
0 new messages