Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Docker Volumes

Philipp Wakonigg edited this page Aug 10, 2017 · 4 revisions

The project makes use of Docker Volumes, which are generated for each Jupyter Notebook Service. Therefore, the JupyterHub SwarmSpawner got modified to allow the advanced driver configuration of Docker Volumes.

In the jupyterhub_config.py file one can define options, which the SwarmSpawner uses to create a new service (notebook). In my scenario the config looks like this:

mounts = [{'type' : 'volume',
'target' : os.environ.get('SWARMSPAWNER_NOTEBOOK_DIR'),
'source' : 'jupyterhub-user-{username}',
'no_copy' : True,
'driver_config' : {
  'name' : 'local',
  'options' : {
     'type' : 'nfs4',
	 'o' : 'addr='+os.environ.get('NFSSERVER_IP')+',rw',
	 'device' : ':'+os.environ.get('NFSSERVER_USERDATA_DEVICE')
   }
}},{
'type' : 'volume',
'target' : '/srv/nbgrader/exchange',
'source' : 'jupyter-exchange-volume',
'no_copy' : True,
'driver_config' : {
  'name' : 'local',
  'options' : {
     'type' : 'nfs4',
	 'o' : 'addr='+os.environ.get('NFSSERVER_IP')+',rw',
	 'device' : ':'+os.environ.get('NFSSERVER_ASSIGNMENTDATA_DEVICE')
   }
}}]

...

c.SwarmSpawner.container_spec = {
			'args' : ['start-singleuser.sh'],
            'Image' : os.environ.get('SWARMSPAWNER_NOTEBOOK_IMAGE'),
			'mounts' : mounts
          }

This configuration instructs the SwarmSpawner to create two volumes, which are later mounted into the service (notebook). The mount array consists of objects, which represents "mount" configurations. It can be compared with this Docker Documentation, where a new "NFS Volume" is created.

docker volume create --driver local
--opt type=nfs
--opt o=addr=192.168.1.1,rw
--opt device=:/path/to/dir
foo


NOTES

I first tried to use 'type' : 'nfs', which did not work out very well, but with nfs4 everything works smooth.

This Docker Volumes come very handy in a DockerSwarm Setup, because if you like to mount stuff in docker services in an other way, you can't 💃. Docker service currently does not support --privileged or --sys-cap-add.

We don't actually want to do this. There are number of things that are hard or impossible to support in a clustered environment. There are other things that are downright insecure, such as privileged, that need to be rethought. https://github.com/docker/swarmkit/issues/1030

You won't find it here too. So the only way to mount something in a service is achieved with Docker Volumes.

Clone this wiki locally