question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mount different volumes based on userlist/group

See original GitHub issue

Is it possible to mount different images based on the username/group (provided by ldapauthenticator in my case).

I currently have a config as follows, but would need a 4th (shared) volume for a selected group of users.

c.DockerSpawner.volumes = {
                       'jupyterhub-userhome-{username}': { 'bind': notebook_dir , 'mode': 'rw'},
                       'jupyterhub-user-{username}': { 'bind': notebook_dir + 'work/' , 'mode': 'rw'},
                       'juypterhub-shared-data': { 'bind': '/home/jovyan/work/shared-ro', 'mode': 'ro'},
}

I wouldn’t mind to hardcode these users in the config as they almost never change.

I tried using a dict using templating to select the correct value - but it seems that templating does not apply here and jupyterhub fails to start.

volumedict = {'superuser': {
                        'jupyterhub-userhome-{username}': { 'bind': notebook_dir , 'mode': 'rw'},
                        'jupyterhub-user-{username}': { 'bind': notebook_dir + 'work/' , 'mode': 'rw'},
                        'juypterhub-shared-data': { 'bind': '/home/jovyan/work/shared-ro', 'mode': 'ro'},
                        'jupyterhub_test_mount': { 'bind': '/home/jovyan/test', 'mode': 'rw'},

                },
              'other': {
                        'jupyterhub-userhome-{username}': { 'bind': notebook_dir , 'mode': 'rw'},
                        'jupyterhub-user-{username}': { 'bind': notebook_dir + 'work/' , 'mode': 'rw'},
                        'juypterhub-shared-data': { 'bind': '/home/jovyan/work/shared-ro', 'mode': 'ro'},
                        }
                }
c.DockerSpawner.volumes = volumedict['{% "superuser" if username == "xmatthias" else "other"%}']

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
cmsealcommented, Oct 30, 2018

@xmatthias this now works for me. Hope it helps you!

from dockerspawner import DockerSpawner
class MyDockerSpawner(DockerSpawner):
    team_map = {
        'username1': 'team-a',
        'username2': 'team-b',
        'username3': 'team-a',
    }

    def start(self):
        if self.user.name in self.team_map:
            team = self.team_map[self.user.name]
            # add team volume to volumes
            self.volumes['/directory/jupyterhub-team-{}'.format(team)] = {
                'bind': '/home/jovyan/teamfolder',
                'mode': 'rw',  # or ro for read-only
            }
        return super().start()

c.JupyterHub.spawner_class = MyDockerSpawner
2reactions
cmsealcommented, Dec 2, 2019

@jameholme If you just want a single shared folder that all users have read/write access to, you could add this to your jupyterhub_config.py:

c.DockerSpawner.volumes = { 'jupyterhub-user-{username}':'/home/jovyan/work', 'jupyterhub-shared':'/home/jovyan/shared', }

This assumes you already have 'jupyterhub-user-{username}':'/home/jovyan/work', as a docker volume per user… if not, just omit that bit.

The earlier code is for having separate volumes for groups/teams. If you don’t need that, you don’t need any of that code, and just the line above.

Note: depending on your setup, you may have to create the jupyterhub-shared volume from the docker cli before it can be used, and I’ve also previously had to manually set file permissions inside the volume before users could actually write to it. Again, this may depend on your setup and configuration. Hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker-compose set user and group on mounted volume
To achieve the desired behavior without changing owner / permissions on the host system do the following steps.
Read more >
What is a prescriptive way for managing the permissions for ...
Use the same user and group between containers and mounted volumes. Use ACLs to control the permissions. Is there a recommended approach for ......
Read more >
Mounting volume/partition with permissions for user
Some solutions I've read about include: changing ownership of the mount point with chown. adding group write permissions with chmod.
Read more >
5.3.5. Displaying Volume Groups Red Hat Enterprise Linux 6
The vgdisplay command displays volume group properties (such as size, extents, number of physical volumes, and so on) in a fixed form. The...
Read more >
Volumes - Docker Documentation
The following example modifies the one above but mounts the directory as a read-only volume, by adding ro to the (empty by default)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found