-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjlab
executable file
·47 lines (41 loc) · 1 KB
/
jlab
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
#!/bin/bash
#set -x
CONTAINER_NAME=jlab
DOCKER_IMAGE=andrespp/jupyterlab
is_running(){
# Returns (echo) CONTAINER ID if container exists and is running, and
# zero length string otherwise
id=$(docker ps -q -f status=running -f name=$CONTAINER_NAME)
echo $id
}
open_browser() {
for i in `seq 10` ; do
CONTAINER_ID=$(is_running)
if [ ! -z $CONTAINER_ID ] ; then
URL=$(docker exec $CONTAINER_NAME /entrypoint.sh geturl)
if [ ! -z $URL ] ; then
echo python -m webbrowser -t $URL
python -m webbrowser -t $URL
exit 0
else
continue
fi
else
sleep 1
fi
done
}
## main()
# Check container status
CONTAINER_ID=$(is_running)
if [ -z $CONTAINER_ID ] ; then
# Container not running, start it
docker run --name jlab --rm -v "$PWD":/opt/app/data -p 8888:8888 \
-p 8787:8787 -d -e KEYMAP=vim $DOCKER_IMAGE
# Open JupyterLab
open_browser
else
echo JupyterLab already running \($CONTAINER_ID\). $URL
URL=$(docker exec jlab /entrypoint.sh geturl)
python -m webbrowser -t $URL
fi