Skip to content

Instantly share code, notes, and snippets.

@jbarratt
Created June 29, 2016 20:36
Show Gist options
  • Save jbarratt/090a0e73225f82e528badbf290c6670c to your computer and use it in GitHub Desktop.
Save jbarratt/090a0e73225f82e528badbf290c6670c to your computer and use it in GitHub Desktop.
Remote Jupyter Notebook Helper
josh@jump:~$ ./bin/notebook.sh
Container not running, starting up
55d2f299de8e7d6683b81817556cf7bd4f627740fefe30457019a8f88c1631b7
In another terminal (or exit this and reconnect) then run:
ssh -L 8080:localhost:32771 josh@jump.XYZ
Then open your browser to http://localhost:8080
When you're done, save system resources by running
./bin/notebook.sh clean
josh@jump:~$ ./bin/notebook.sh
Container already running
In another terminal (or exit this and reconnect) then run:
ssh -L 8080:localhost:32771 josh@jump.XYX
Then open your browser to http://localhost:8080
When you're done, save system resources by running
./bin/notebook.sh clean
josh@jump:~$ ./bin/notebook.sh clean
Cleaning up container
josh_notebook
josh_notebook
#!/bin/bash
## Manage a jupyter notebook container automatically.
## start (or by default if no arg is given)
## Checks to see if the container is started
## If so, leaves it running, else, starts it
## Prints the ssh command to connect to it
##
## clean
# Finds the container, stops, removes it
WORKDIR=$HOME/work/notebooks
CONTAINERNAME="${USER}_notebook"
clean() {
echo "Cleaning up container"
docker stop $CONTAINERNAME
docker rm $CONTAINERNAME
}
launch() {
RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINERNAME 2> /dev/null)
if [ "$RUNNING" != "true" ];then
echo "Container not running, starting up"
mkdir -p $WORKDIR
sudo chgrp 100 $WORKDIR
docker run -d -v $WORKDIR:/home/jovyan/work --name $CONTAINERNAME -P jupyter/datascience-notebook start-notebook.sh
else
echo "Container already running"
fi
PORT=$(docker port $CONTAINERNAME | cut -d ':' -f 2)
echo -e "In another terminal (or exit this and reconnect) then run:\n\tssh -L 8080:localhost:$PORT $USER@$HOSTNAME"
echo "Then open your browser to http://localhost:8080"
echo -e "When you're done, save system resources by running\n\t$0 clean"
}
if [ "$1" == "clean" ]; then
clean
else
launch
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment