From 213c12e82a8d31147be72bc8fa214207fb47c86c Mon Sep 17 00:00:00 2001 From: Matt Wiese Date: Fri, 28 Jul 2023 15:02:19 -0400 Subject: [PATCH] Add initial_user traitlet to change user that container is started with --- dockerspawner/dockerspawner.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dockerspawner/dockerspawner.py b/dockerspawner/dockerspawner.py index f2debe0a..df28fcae 100644 --- a/dockerspawner/dockerspawner.py +++ b/dockerspawner/dockerspawner.py @@ -195,6 +195,23 @@ def _port_default(self): def _ip_default(self): return "0.0.0.0" + initial_user = Unicode( + "jovyan", + help=""" + The initial user with which to start the container + + The [default user for Jupyter Docker stacks](https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html#jupyter-docker-stacks-foundation) is 'jovyan' + + You may need to set this value to 'root', which is equivalent to + `docker run --user root`. This is necessary when e.g. changing jovyan's + default UID or home directory permissions + + Jupyter Docker stacks will switch back to jovyan before starting the notebook server (e.g. JupyterLab) + The end-user within the container *will not* be the user set here, unless you are using a modified image + """, + config=True, + ) + container_image = Unicode( "jupyterhub/singleuser:%s" % _jupyterhub_xy, help="Deprecated, use `DockerSpawner.image.`", @@ -1123,6 +1140,7 @@ async def create_object(self): volumes=self.volume_mount_points, name=self.container_name, command=(await self.get_command()), + user=self.initial_user, ) # ensure internal port is exposed