Is it possible to get different docker image for each user?

I’m using dockerspawner in jupyterhub.
Is it possible to get different docker image for each user?

Yes, if you customize DockerSpawner a bit. The image is self.image and the user is self.user, so you can e.g. try this in jupyterhub_config.py:

def image_for_user(user):
    "Given a user, return the right image"""
    if user.name == "me":
        return "jupyter/scipy-notebook:f646d2b2a3af"
    else:
        return "jupyter/base-notebook:f646d2b2a3af"

from dockerspawner import DockerSpawner

class MyDockerSpawner(DockerSpawner):
    def start(self):
        self.image = image_for_user(self.user)
        return super().start()

c.JupyterHub.spawner_class = MyDockerSpawner

where you put your logic for finding images in image_for_user(). You might want to make it an async method, depending on how you look up this info.

3 Likes

Thank you.
You’ve been a great help!