Skip to content

Instantly share code, notes, and snippets.

@jhamrick
Last active April 11, 2020 16:27
Show Gist options
  • Save jhamrick/45f01c1a15572e964e5b to your computer and use it in GitHub Desktop.
Save jhamrick/45f01c1a15572e964e5b to your computer and use it in GitHub Desktop.
nbgrader docker image

Assuming you are in the directory with the Dockerfile, build the image with:

docker build -t jupyter/nbgrader .

Then, cd to the root of you nbgrader directory and run:

NBGRADER="docker run --rm -v $(pwd):/assignments/ jupyter/nbgrader"

(This command tells docker to run the jupyter/nbgrader image and mount the current directory inside the container at the path /assignments, and to remove the docker container when the command has finished).

Now, you can use ${NBGRADER} rather than nbgrader to run your nbgrader commands, e.g.:

${NBGRADER} assign "Problem Set 1"
${NBGRADER} autograde "Problem Set 1"

These commands will run nbgrader inside a docker container rather than directly on your machine. Note that this setup does mount your entire nbgrader directory, so it’s possible for students’ code to remove any files within that nbgrader directory. Thus, you should have those backed up somewhere before running the autograder. This setup will protect the rest of the files on the machine, however.

FROM jupyter/notebook
# Install nbgrader
RUN pip2 install nbgrader && pip3 install nbgrader
# Add any other dependencies you might want, e.g. numpy, scipy, etc.
#RUN pip2 install numpy scipy matplotlib
#RUN pip3 install numpy scipy matplotlib
# Configure grader user
RUN useradd -m grader
RUN chown -R grader:grader /home/grader
USER grader
# Where the assignments will live (these need to be mounted on runtime)
WORKDIR /assignments
ENTRYPOINT ["tini", "--", "nbgrader"]
CMD ["--help"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment