/
run_scipy_notebook.sh
executable file
·54 lines (42 loc) · 1.22 KB
/
run_scipy_notebook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -euo pipefail
image=davetang/scanpy:3.11
container_name=scanpy-notebook
port=10000
start_container () {
# If you change the notebook username using the following:
#
# -e NB_USER="my-username" \
#
# You will not be able to list currently running servers to obtain a token.
# Therefore just use the username jovyan
#
# In addition, you need to run as root (`--user root`)
# or else you will not be able to edit mounted files
docker run -d \
--rm \
-p ${port}:8888 \
--user root \
-e NB_UID=$(id -u) \
-e NB_GID=$(id -g) \
-v $(pwd):/home/jovyan/work \
--name ${container_name} \
${image}
>&2 echo ${container_name} listening on port ${port}
>&2 echo -e "Run the following to get the token:\ndocker exec ${container_name} jupyter server list"
}
check_container () {
docker container inspect ${container_name} > /dev/null 2>&1
# $? == 0 if container exists
if [[ $? > 0 ]]; then
start_container
else
>&2 echo ${container_name} already exists
exit 1
fi
}
# the || is necessary for preventing `set -e` immediately exiting
# if the container already exists
check_container || true
>&2 echo Done
exit 0