Skip to content

Instantly share code, notes, and snippets.

@mjkloeckner
Last active September 11, 2024 16:25
Show Gist options
  • Save mjkloeckner/4ede3c2bc30a1d57c5a24f76f68f191b to your computer and use it in GitHub Desktop.
Save mjkloeckner/4ede3c2bc30a1d57c5a24f76f68f191b to your computer and use it in GitHub Desktop.
run jupyter notebook from *nix shell using docker
#!/bin/sh
# https://jupyter-docker-stacks.readthedocs.io/en/latest/index.html
# https://docs.docker.com/reference/cli/docker/container/exec/
systemctl is-active --quiet docker || systemctl start docker
systemctl is-active --quiet containerd || systemctl start containerd
PORT=8888
# if port in use increment port number until port number is available
while $(nc -vz 127.0.0.1 $PORT >/dev/null 2>&1)
do
PORT=$((PORT + 1))
done
test -e "$HOME"/.jupyter || mkdir "$HOME"/.jupyter
docker run \
-it --rm \
-p $PORT:8888 \
-e DOCKER_STACKS_JUPYTER_CMD=notebook \
-e JUPYTERLAB_ENABLED=false \
-v "${PWD}":/home/jovyan/work \
-v "$HOME"/.jupyter/:/home/jovyan/.jupyter \
-d jupyter/datascience-notebook \
start-notebook.py --NotebookApp.token='' --custom-css
test $? -eq 0 && CONTAINER_NAME="$(docker ps -l --format "{{.Names}}")"
echo "Running on container '$CONTAINER_NAME' with address: http://localhost:$PORT"
sleep 3 && explorer.exe "http://localhost:$PORT" >/dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment