jupyterhub-deploy-docker
jupyterhub-deploy-docker copied to clipboard
How to spawn user container with DOCKER_NOTEBOOK_DIR
suppose a user named bob signed in with github, how to spwan a bob container with DOCKER_NOTEBOOK_DIR to /home/bob/work?
I believe the SystemUserSpawner facilitates the scenario you're asking about. I've never used it though.
The single-user docker image would have to include the systemuser.sh script, which just adds the user within the single-user container before starting the notebook server. This script has not made it into the base docker-stacks images yet (see https://github.com/jupyter/docker-stacks/issues/242), but you could just add it yourself in a custom image.
Forcing the single-user containers to be aware of individual users on the host makes things more complicated. This is why this reference implementation uses Docker volumes.
It's easy enough to add the systemuser.sh script to the docker-stacks images. Someone just needs to put in a PR.
Hi, I follow on this issue as I need to do a similar thing : use the jupyterhub-deploy-docker with SystemUserSpawner. I did add the systemuser.sh script to the notebook image and set the DOCKER_SPAWN_CMD to execute it. However when I start my server I keep hitting a
KeyError: 'getpwnam(): name not found: thomas'
I guess I must be missing something somewhere because it seems the user isn't created, but I can't figure out... Thanks :)
I've never used SystemUserSpawner. It sure looks like the systemuser.sh script should add the user to the notebook container. Can you docker exec into the container to see if user thomas exists?
/cc @parente @minrk
Actually I can't check in the notebook container as it won't start. Does the Jupyterhub container needs also to be aware of the users ? The way spawners work may not be clear in my head :)
SystemUserSpawner is best suited to the Hub running on the host (not in a container) and users in containers, but it can be done. To get this to work with SystemUserSpawner, you need to ensure that the users on the system exist in the Hub's container. This can be done by mounting /etc/passwd and possibly another file or two into the Hub's container. You can verify this in the Hub container by checking that the thomas user exists (in the Hub container).
In Python:
import pwd
pw = pwd.getpwnam('thomas')
print(pw.pw_dir)
I have user called myuser on my host machine. I mounted the /etc/passwd and /etc/shadow files in the Hub's container. I verified the user exists in the Hub's container with the example code:
import pwd
pw = pwd.getpwnam('myuser')
print(pw.pw_dir)
I passed the myuser to the SystemUserSpawner in my jupyter_config.py using:
c.DockerSpawner.extra_create_kwargs.update({'user': 'myuser'})
However, when the myuser notebook container tries to spawn i get the following error:
Traceback (most recent call last):
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/tornado/web.py", line 1469, in _execute
jupyterhub | result = yield result
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/jupyterhub/handlers/base.py", line 535, in get
jupyterhub | yield self.spawn_single_user(current_user)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/jupyterhub/handlers/base.py", line 328, in spawn_single_user
jupyterhub | yield gen.with_timeout(timedelta(seconds=self.slow_spawn_timeout), f)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/jupyterhub/user.py", line 255, in spawn
jupyterhub | raise e
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/jupyterhub/user.py", line 229, in spawn
jupyterhub | ip_port = yield gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/dockerspawner/dockerspawner.py", line 413, in start
jupyterhub | yield self.docker('start', self.container_id, **start_kwargs)
jupyterhub | File "/opt/conda/lib/python3.5/concurrent/futures/_base.py", line 398, in result
jupyterhub | return self.__get_result()
jupyterhub | File "/opt/conda/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
jupyterhub | raise self._exception
jupyterhub | File "/opt/conda/lib/python3.5/concurrent/futures/thread.py", line 55, in run
jupyterhub | result = self.fn(*self.args, **self.kwargs)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/dockerspawner/dockerspawner.py", line 289, in _docker
jupyterhub | return m(*args, **kwargs)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/docker/utils/decorators.py", line 21, in wrapped
jupyterhub | return f(self, resource_id, *args, **kwargs)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/docker/api/container.py", line 383, in start
jupyterhub | self._raise_for_status(res)
jupyterhub | File "/opt/conda/lib/python3.5/site-packages/docker/client.py", line 174, in _raise_for_status
jupyterhub | raise errors.APIError(e, response, explanation=explanation)
jupyterhub | docker.errors.APIError: 500 Server Error: Internal Server Error ("b'{"message":"linux spec user: unable to find user myuser: no matching entries in passwd file"}'")
Am I approaching this the right way?