Last active
September 11, 2024 16:25
-
-
Save mjkloeckner/4ede3c2bc30a1d57c5a24f76f68f191b to your computer and use it in GitHub Desktop.
run jupyter notebook from *nix shell using docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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