-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.py
49 lines (44 loc) · 1.24 KB
/
docker.py
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
import re
import pathlib
DOCKER_PORT = 8888
HOST_PORT = 60000 # 60000-61000 are available (used by mosh, but we don't use mosh)
WORKDIR = '/home/jovyan/'
# IMAGE = 'quay.io/jupyter/pytorch-notebook'
# IMAGE = 'jupyter-tinygrad'
IMAGE = 'quay.io/jupyter/scipy-notebook'
LOCALDIR = pathlib.Path('~/python/').expanduser()
CIDFILE = '/tmp/docker_cid'
def run(HOST_PORT=60000,
notebook_name='notebook',
notebook_type=IMAGE
):
cmd = [
'docker',
'run',
'-p', f'{HOST_PORT}:{DOCKER_PORT}',
f'--cidfile={CIDFILE}',
'-e', 'CHOWN_HOME=yes',
'-e', 'GRANT_SUDO=yes',
'-e', "CHOWN_HOME_OPTS='-R'",
# necessary for initializing new host folder
# can be omitted for further accesses to LOCALDIR
'--user', 'root',
'-v', f'{LOCALDIR}/{notebook_type}/{notebook_name}:{WORKDIR}',
'-w', f'{WORKDIR}',
f'{notebook_type}'
]
return cmd
def docker_kill_command(pid):
cmd = [
'docker',
'kill',
f'{pid}'
]
return cmd
def get_token(url):
pattern = '^.*token=([0-9a-f]*)$'
m = re.match(pattern, url)
return m.group(1)
if __name__ == "__main__":
print('The docker command is:')
print(' '.join(run()))