Skip to content

Commit

Permalink
makes additional ports optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert van Geest committed Jan 9, 2025
1 parent 1252c97 commit 53fd4d7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions run_jupyter_notebooks
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ This command generates docker containers based on a jupyter notebook container f
-m maximum memory for the user container. Default: 16g.\n
-c maximum number of cpu for the user container. Default: 4.\n
-n container name prefix. Default: jupyter \n
-a add admin container[yes/no]. Default: yes"
-a add admin container[yes/no]. Default: yes \n
-d add an additional port at port-2000 [yes/no]. Default: no"

while getopts ":i:u:p:m:c:n:a:" opt
while getopts ":i:u:p:m:c:n:a:d:" opt
do
case $opt in
i)
Expand All @@ -36,6 +37,9 @@ do
a)
ADD_ADMIN=$OPTARG
;;
d)
ADD_PORT=$OPTARG
;;
\?)
echo -e "Invalid option: -$OPTARG \n" >&2
echo -e $USAGE >&2
Expand Down Expand Up @@ -67,6 +71,7 @@ if [ "$MEMORY" == "" ]; then MEMORY=16g; fi
if [ "$CPU" == "" ]; then CPU=4; fi
if [ "$CONTAINER_NAME" == "" ]; then CONTAINER_NAME=jupyter; fi
if [ "$ADD_ADMIN" == "" ]; then ADD_ADMIN=yes; fi
if [ "$ADD_PORT" == "" ]; then ADD_PORT=no; fi

# create general volume that will be populated with read-only data
docker volume create data
Expand Down Expand Up @@ -113,6 +118,13 @@ do
# generate container for each user
# mount user volume, data volume (general, read only) and group work volume (general, read and write)
# the permissions of general volumes (data and group work) need to be changed with the master container (this can probably be coded as well)
if [ "$ADD_PORT" == "yes" ]
then
ADD_PORT="-p $((port-2000)):$((port-2000))"
else
ADD_PORT=""
fi

docker run \
-d \
--cpus=$CPU \
Expand All @@ -128,7 +140,7 @@ do
-e JUPYTER_ENABLE_LAB=yes \
-e JUPYTER_TOKEN=$password \
-p $port:8888 \
-p $((port-2000)):$((port-2000)) \
"$ADD_PORT" \
$IMAGE \
start-notebook.sh
done
Expand All @@ -143,4 +155,4 @@ done

# to add https:
# --ServerApp.keyfile=/etc/ssl/notebook/notebook.key \
# --ServerApp.certfile=/etc/ssl/notebook/notebook.pem
# --ServerApp.certfile=/etc/ssl/notebook/notebook.pem

0 comments on commit 53fd4d7

Please sign in to comment.