-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_docker_jupyter.py
executable file
·39 lines (31 loc) · 1.16 KB
/
run_docker_jupyter.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
import argparse
import errno
import os
import shutil
HOME_DIRECTORY = '/home/docker'
def main():
parser = argparse.ArgumentParser(add_help=True, description='Run docker image.')
parser.add_argument("--command", "-c", default="jupyter-notebook --ip 0.0.0.0")
parser.add_argument("--docker_tag", "-t", default='lucidyan/ml-docker:20.02.2',
help='Docker image tag')
parser.add_argument("--port_jupyter", "-pj", default='8888', help='External Jupyter Notebook port')
parser.add_argument("--port_tensorboard", "-pt", default='6006', help='External Tensorboard port')
args = parser.parse_args()
gpu_option = ''
if shutil.which('nvidia-smi') is not None:
gpu_option = ' --gpus all'
run_command = (
'docker run'
' --rm'
' -it'
' --ipc=host'
f'{gpu_option}'
f' -p {args.port_jupyter}:8888 -p {args.port_tensorboard}:6006'
f' -v {os.getcwd()}/notebooks:{HOME_DIRECTORY}/notebooks'
f' {args.docker_tag}'
f' {args.command}'
)
print('Running command:\n' + run_command + '\n')
os.system(run_command)
if __name__ == '__main__':
main()