Closed ddcamiu closed 7 years ago
Hi @ddcamiu,
as a dockerfile you can start from here. But instead of using dockerspawner you should put SwarmSpawner (better to use the git repository).
About the configuration, there is nothing special, it works exactly like the dockerspawner but you need to initialize the Swarm before.
Since there is an open ticket about the Jupyterhub Dockerfile, though I would ask this in case I'm doing something really stupid. For some reason, it doesn't seem to import SwarmSpawner at all, and so I get an error: The 'spawner_class' trait of <jupyterhub.app.JupyterHub object at 0x7fa6c8b19f98> instance must be a type, but 'cassinyspawner.SwarmSpawner' could not be imported
This is a bit odd because I have done the exact same thing with other Dockerfile (e.g., with dockerspawner) and it works fine.
Any thoughts?
In my Dockerfile, I inherited from jupyterhub/jupyterhub as follows:
FROM jupyterhub/jupyterhub
RUN python -m pip install git+https://github.com/cassinyio/SwarmSpawner
My jupyterhub_config.py
file is simple, and follows the example, except for specifying the image to be jupyterhub/singleuser
for the services, and comments the resource_spec
until I figure out the cpu and mem reservation:
c = get_config()
pwd = os.path.dirname(__file__)
print("I'm stuck in a config file, please help me")
c.JupyterHub.spawner_class = 'cassinyspawner.SwarmSpawner'
c.JupyterHub.ip = '0.0.0.0'
c.JupyterHub.hub_ip = '0.0.0.0'
c.JupyterHub.cleanup_servers = False
# First pulls can be really slow, so let's give it a big timeout
c.SwarmSpawner.start_timeout = 60 * 5
c.SwarmSpawner.jupyterhub_service_name = 'jupyterhub'
c.SwarmSpawner.networks = ["jupyterhub"]
notebook_dir = os.environ.get('NOTEBOOK_DIR') or '/home/jovyan/work'
c.SwarmSpawner.notebook_dir = notebook_dir
mounts = [{'type' : 'volume',
'source' : 'jupyterhub-user-{username}',
'target' : notebook_dir}]
c.SwarmSpawner.container_spec = {
# The command to run inside the service
'args' : ['/usr/local/bin/start-singleuser.sh'], #(string or list)
'Image' : 'jupyterhub/singleuser',
'mounts' : mounts
}
Deploying with
docker service create -t -p 8000:8000 --mount
type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock --moun
type=bind,src=/root/SwarmSpawner/jupyterhub_config.py,dst=/srv/jupyterhub/jupyterhub_config.py
--name jupyterhub --network jupyterhub huwf/jupyterhub
Can you try following the README?
git clone https://github.com/cassinyio/SwarmSpawner
cd SwarmSpawner
pip install -r requirements.txt
python setup.py install
Yes, that works. I did try doing something like that, but for some reason git clone
gave me an empty working directory which meant I couldn't build the container at all, which was why I went for the pip install git+
option. Doing git clone
and then ADD
in the Dockerfile worked okay.
I looked in a bit more detail at the pip documentation, so won't make this mistake again. Sorry about that!
Huw
Hi @huwf no problem :)
I assume the SwarmSpawner is configured as part of a Docker service that runs JupyterHub. Could you share a sample configuration of that service, e.g. which base image is used?