How can I pre-populate the lab books with content?

Using JupyterHub and deploying on Google’s GKE, I am attempting to create student notebooks that would be prepopulated with content — something a little like this, but with far more ipynb files, etc:

In order to include such content in the basic lab notebook, I have turned to tweaking the various images — based on the instructions in Customize an existing Docker image.

In my struggles to figure out what is wrong, I have been using jupyter/base-notebook:latest and have created a Dockerfile that, now and then, looks like this:

FROM jupyter/base-notebook:latest
USER root
ENV NB_UID=$NB_UID
ENV NB_GID=$NB_GID
WORKDIR /home/jovyan
ADD "main.py" .
RUN chown -R $NB_UID:$NB_GID /home/jovyan/main.py
USER $NB_USER

and push the image to my public repo at hub.docker.com.

(The file main.py is in the directory of the Dockerfile. At times I’ve changed /home/jovyan to $HOME and some other tweaks like changing ADD to COPY.)

The last several iterations has my config.yaml looking thus:

singleuser:
  image:
    name: myrepo/base-notebook
    tag: version04

But no matter how I tweak this, when I log in as any given user, I am staring at the standard lost+found directory of Jupyter Lab. All the features work and I always open a terminal in the lab book to see if I can find something copied somewhere. But no luck.

I am throwing no errors on build or helm upgrade. The site allows login, and, as I said, everything else works.

Am I complete off or is it an error staring me in the face?

Thanks.

P.S. I have been on this forum for months and have searched and read many postings. I’ve posted this as a sort of last resort.

I have, for now, surmounted this hurdle. I did so by adding/copying files to the /tmp directory and then, via my config.yaml for the helm chart, copying those over to the /home/joyvan directory.

So now the skeletal example from the Dockerfile:

FROM jupyter/base-notebook:latest
USER root
ADD main.py /tmp

with main.py in the same directory as the Dockerfile.

(And, of course, pushing this to the hub.docker.com repo.)

Then in config.yaml:

singleuser:
  image:
    name: myrepo/base-notebook
    tag: version05

  lifecycleHooks:
    postStart:
      exec:
        command: ["cp", "-r", "/tmp", "/home/jovyan"]

Note: I am leaving this up in the event others are likewise struggling.

I’ll finally note that this solution is found in User files and adding storage. And, yes, you can say, “Why didn’t you … ?”, but none of this is intuitive and the earlier text on that very same page suggests this step as unnecessary.

No worries, though. I promise I’ll be back with other problems.

1 Like