-
Notifications
You must be signed in to change notification settings - Fork 2
/
mldock.sh
executable file
·839 lines (755 loc) · 24.2 KB
/
mldock.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#!/bin/bash
set -e
# set -x # Debug: be verbose
# PS4='$LINENO: ' # Add lines number to debug output
## Main CLI function
## =================
app_name=mldock
repository="omeryair/"
image_name="mldock"
version_name="v0.9"
container_name="mldock_$USER"
pass_ssh_key=false
print_command=false
# print_command=true
main_cli() {
## Parse args
## ==========
usage() {
echo "A CLI tool for working with the $app_name docker"
echo ""
echo "usage: $app_name <command> [<options>]"
echo " setup Create a link or a copy of the $app_name.sh script in the /usr/bin folder (requiers sudo)."
echo " setup_remote Install docker and nvidia-docker on a remote machine."
echo " build Build the image."
echo " run Run a command inside a new container."
echo " run_server Run the default mldock server."
echo " run_remote Run a command inside a new container on a remote machine."
echo " exec Execute a command inside an existing container."
echo " exec_remote Execute a command inside an existing container on a remote machine."
echo " stop Stop a running container."
echo "Use $app_name <command> -h for specific help on each command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts ":h" opt; do
case $opt in
h )
usage
exit 0
;;
\? )
echo "Error: Invalid Option: -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -lt 1 ]; then
echo "Error: Was expecting a command" 1>&2
usage
exit 1
fi
subcommand=$1; shift
ref_dir="$( cd $( dirname "$(readlink -f ${BASH_SOURCE[0]})" ) && pwd )"
case "$subcommand" in
setup)
setup_cli "$@"
;;
setup_remote)
setup_remote_cli "$@"
;;
build)
build_cli "$@"
;;
run)
run_cli "$@"
;;
run_server)
run_server_cli "$@"
;;
run_remote)
run_remote_cli "$@"
;;
exec)
exec_cli "$@"
;;
exec_remote)
exec_remote_cli "$@"
;;
stop)
stop_cli "$@"
;;
*)
echo "Error: unknown command $subcommand" 1>&2
usage
exit 1
esac
}
setup_cli() {
copy_script_file=false
usage () {
echo "Create a link or a copy of the $app_name.sh script in the /usr/bin folder (requiers sudo)."
echo ""
echo "usage: $app_name $subcommand"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -c Copy the script file to /usr/bin. By default a link is created to the current file."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts "c" opt; do
case $opt in
c)
copy_script_file=true
;;
:)
echo "Error: -$opt requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -gt 0 ]; then
echo "Error: Unexpected arguments: $@" 1>&2
usage
exit 1
fi
run_setup
}
setup_remote_cli() {
usage () {
echo "Setup docker and nvidia-docker a remote machine"
echo ""
echo "usage: $app_name $subcommand remote_ip"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
if [ "$#" -lt 1 ]; then
echo "Error: Was expecting a remote ip" 1>&2
usage
exit 1
fi
remote_ip=$1; shift
run_setup_remote
}
build_cli() {
tag_as_latest=true
usage () {
echo "Build the image"
echo ""
echo "usage: $app_name $subcommand [<options>]"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -v version_name The version name to use for the build image. Default: \"$version_name\""
echo " -l Don't tag built image as latest"
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts "v:l" opt; do
case $opt in
v)
version_name=$OPTARG
;;
l)
tag_as_latest=false
;;
:)
echo "Error: -$opt requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -gt 0 ]; then
echo "Error: Unexpected arguments: $@" 1>&2
usage
exit 1
fi
check_docker_for_sudo
build_image
}
run_cli() {
container_name=""
if xhost >& /dev/null ; then
## Display exist
connect_to_x_server=true
else
## No display
connect_to_x_server=false
fi
if [[ "$(whoami)" == "root" ]]; then
userstring="dockuser:4283:dockuser:4283"
else
userstring="$(whoami):$(id -u):$(id -gn):$(id -g)"
fi
map_host=true
detach_container=false
home_folder="$HOME"
working_folder="$PWD"
command_to_run=""
use_tmux=false
extra_args=()
if nvidia-smi >& /dev/null ; then
use_nvidia_runtime=true
if docker run --rm --runtime=nvidia busybox echo test >& /dev/null ; then
use_gpus_all=false
else
use_gpus_all=true
fi
else
use_nvidia_runtime=false
fi
usage () {
echo "Run a command inside a new container"
echo ""
echo "usage: $app_name $subcommand [<options>] [command]"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -v version_name The version name to use for the build image. Default: \"$version_name\""
echo " -c container_name The name to for the created container. Default: \"$container_name\""
echo " -f home_folder A folder to map as the dockuser's home folder. Default: \"$home_folder\""
echo " -w working_folder The working folder."
echo " -s Run the command as root."
echo " -u Run the command as dockuser user."
echo " -i username Run the command as *username*."
echo " -x Don't connect X-server"
echo " -r Don't map the root folder on the host machine to /host inside the container."
echo " -d Detach the container."
echo " -t Run in at TMUX session."
echo " -e extra_args Extra arguments to pass to the docker run command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts "v:c:f:w:sui:xrdte:" opt; do
case $opt in
v)
version_name=$OPTARG
;;
c)
container_name=$OPTARG
;;
f)
home_folder=$OPTARG
;;
w)
working_folder=$OPTARG
;;
s)
userstring=""
;;
u)
userstring="dockuser:4283:dockuser:4283"
;;
i)
username=$OPTARG
userstring="$username:$(id -u $username):$(id -gn $username):$(id -g $username)"
;;
x)
connect_to_x_server=false
;;
r)
map_host=false
;;
d)
detach_container=true
;;
t)
use_tmux=true
;;
e)
IFS=$'\n' extra_args=( $(xargs -n1 printf "%s\n" <<< "$OPTARG") )
unset IFS
;;
:)
echo "Error: -$opt requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
userstring="${userstring// /-}"
if [ "$#" -gt 0 ]; then
command_to_run=( "$@" )
fi
check_docker_for_sudo
gen_command
run_command
}
run_server_cli() {
usage () {
echo "Run the default mldock server"
echo ""
echo "This command is equivalent to runing \"mldock run -d -c $container_name run_server\"."
echo "This command share the same arguments of the \"run\" command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
run_cli "$@" -d -c "$container_name" run_server
}
run_remote_cli() {
container_name=""
if xhost >& /dev/null ; then
## Display exist
connect_to_x_server=true
else
## No display
connect_to_x_server=false
fi
if [[ "$(whoami)" == "root" ]]; then
userstring="dockuser:4283:dockuser:4283"
else
userstring="$(whoami):$(id -u):$(id -gn):$(id -g)"
fi
map_host=true
detach_container=false
local_ip=`hostname -I | cut -d " " -f1`
home_folder="$USER@${local_ip}:$HOME"
working_folder="$PWD"
command_to_run=""
use_tmux=false
extra_args=()
usage () {
echo "Run a command inside a new container on a remote machine"
echo ""
echo "usage: $app_name $subcommand remote_ip [<options>] [command]"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -v version_name The version name to use for the build image. Default: \"$version_name\""
echo " -c container_name The name to for the created container. Default: \"$container_name\""
echo " -f home_folder A folder to map as the dockuser's home folder. Default: \"$home_folder\""
echo " -w working_folder The working folder."
echo " -s Run the command as root."
echo " -u Run the command as dockuser user."
echo " -i username Run the command as *username*."
echo " -x Don't connect X-server"
echo " -r Don't map the root folder on the host machine to /host inside the container."
echo " -d Detach the container."
echo " -t Run in at TMUX session."
echo " -e extra_args Extra arguments to pass to the docker run command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
if [ "$#" -lt 1 ]; then
echo "Error: Was expecting a remote ip" 1>&2
usage
exit 1
fi
remote_ip=$1; shift
while getopts "v:c:f:w:sui:xrdte:" opt; do
case $opt in
v)
version_name=$OPTARG
;;
c)
container_name=$OPTARG
;;
f)
home_folder=$OPTARG
;;
w)
working_folder=$OPTARG
;;
s)
userstring=""
;;
u)
userstring="dockuser:4283:dockuser:4283"
;;
i)
username=$OPTARG
userstring="$username:$(id -u $username):$(id -gn $username):$(id -g $username)"
;;
x)
connect_to_x_server=false
;;
r)
map_host=false
;;
d)
detach_container=true
;;
t)
use_tmux=true
;;
e)
IFS=$'\n' extra_args=( $(xargs -n1 printf "%s\n" <<< "$OPTARG") )
unset IFS
;;
:)
echo "Error: -$opt requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
userstring="${userstring// /-}"
if [ "$#" -gt 0 ]; then
command_to_run=( "$@" )
fi
if ssh $remote_ip nvidia-smi >& /dev/null ; then
use_nvidia_runtime=true
if ssh $remote_ip docker run --rm --runtime=nvidia busybox echo test >& /dev/null ; then
use_gpus_all=false
else
use_gpus_all=true
fi
else
use_nvidia_runtime=false
fi
if [ -f "$HOME/.ssh/id_rsa.mldock" ]; then
pass_ssh_key=true
fi
gen_command
run_remote_command
}
exec_cli() {
extra_args=()
command_to_run="bash"
working_folder="$PWD"
usage () {
echo "Execute a command inside an existing container"
echo ""
echo "usage: $app_name $subcommand [<options>] [command_to_run]"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -c container_name The name to for the created container. default: \"$container_name\""
echo " -w working_folder The working folder."
echo " -e extra_args Extra arguments to pass to the docker exec command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts "c:u:e:" opt; do
case $opt in
c)
container_name=$OPTARG
;;
w)
working_folder=$OPTARG
;;
e)
IFS=$'\n' extra_args=( $(xargs -n1 printf "%s\n" <<< "$OPTARG") )
unset IFS
;;
:)
echo "Error: -$OPTARG requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -gt 0 ]; then
command_to_run=( "$@" )
fi
check_docker_for_sudo
gen_exec_command
run_command
}
exec_remote_cli() {
extra_args=()
working_folder="$PWD"
usage () {
echo "Execute a command inside an existing container"
echo ""
echo "usage: $app_name $subcommand remote_ip [<options>] [command_to_run]"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -c container_name The name to for the created container. default: \"$container_name\""
echo " -w working_folder The working folder."
echo " -e extra_args Extra arguments to pass to the docker exec command."
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
remote_ip=$1; shift
while getopts "c:u:e:" opt; do
case $opt in
c)
container_name=$OPTARG
;;
w)
working_folder=$OPTARG
;;
e)
IFS=$'\n' extra_args=( $(xargs -n1 printf "%s\n" <<< "$OPTARG") )
unset IFS
;;
:)
echo "Error: -$OPTARG requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -gt 0 ]; then
command_to_run=( "$@" )
fi
gen_exec_command
run_remote_command
}
stop_cli() {
usage () {
echo "Stop a running container."
echo ""
echo "usage: $app_name $subcommand"
echo " or: $app_name $subcommand -h to print this help message."
echo "Options:"
echo " -c container_name The name to for the created container. default: \"$container_name\""
}
if [ "$#" -eq 1 ] && [ "$1" == "-h" ]; then
usage
exit 0
fi
while getopts "c:u:e:" opt; do
case $opt in
c)
container_name=$OPTARG
;;
:)
echo "Error: -$opt requires an argument" 1>&2
usage
exit 1
;;
\?)
echo "Error: unknown option -$opt" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ "$#" -gt 0 ]; then
echo "Error: Unexpected arguments: $@" 1>&2
usage
exit 1
fi
check_docker_for_sudo
stop_container
}
check_docker_for_sudo() {
if ! docker ps >& /dev/null; then
if sudo docker ps >& /dev/null; then
docker_sudo_prefix="sudo "
else
echo "!! Error: was not able to run \"docker ps\""
exit
fi
else
docker_sudo_prefix=""
fi
}
run_setup() {
if [ "$copy_script_file" = true ]; then
echo "-> Creating a copy of $ref_dir/$app_name.sh at /usr/bin/$app_name"
sudo cp --remove-destination $ref_dir/$app_name.sh /usr/bin/$app_name
else
echo "-> Creating a symbolic link to $ref_dir$app_name.sh at /usr/bin/$app_name"
sudo ln -sfT $ref_dir/$app_name.sh /usr/bin/$app_name
fi
}
run_setup_remote() {
if [ "$print_command" = true ]; then
echo "Running on $remote_ip: ${cmd[@]}"
echo ""
fi
echo "-> Install docker"
ssh $remote_ip -t sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common # allow apt to use a repository over HTTPS
ssh $remote_ip -t "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -" # Add Docker’s official GPG key
ssh $remote_ip -t echo "\"deb [arch=amd64] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable\""
ssh $remote_ip -t sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \"\$(lsb_release -cs)\" stable"
ssh $remote_ip -t sudo apt-get update || true
ssh $remote_ip -t sudo apt-get install -y docker-ce
echo "-> Add user to the docker group"
ssh $remote_ip -t sudo groupadd docker || true
ssh $remote_ip -t sudo usermod -aG docker \"\$USER\"
echo "-> Install nvidia-docker"
ssh $remote_ip -t curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
ssh $remote_ip -t ". /etc/os-release; curl -s -L \"https://nvidia.github.io/nvidia-docker/\$ID\$VERSION_ID/nvidia-docker.list\" | sudo tee /etc/apt/sources.list.d/nvidia-docker.list"
ssh $remote_ip -t sudo apt-get update
ssh $remote_ip -t sudo apt-get install -y nvidia-docker2
echo "-> Restart the docker service"
ssh $remote_ip -t sudo pkill -SIGHUP dockerd
}
build_image() {
echo "-> Building image from $ref_dir"
${docker_sudo_prefix}docker build -t $repository$image_name:$version_name $ref_dir
if [ "$tag_as_latest" = true ]; then
${docker_sudo_prefix}docker tag $repository$image_name:$version_name $repository$image_name:latest
fi
}
gen_command() {
# # if [ "user_host_user" = true ]; then
# if [ true = true ]; then
# extra_args="-v /etc/passwd:/etc/passwd -u $(id -u ${USER}):$(id -g ${USER})"
# fi
if [ "$connect_to_x_server" = true ]; then
xhost +local:root > /dev/null
extra_args+=("-e" "DISPLAY=${DISPLAY}" "-e" "MPLBACKEND=Qt5Agg" "-e" "QT_X11_NO_MITSHM=1" "-v" "/tmp/.X11-unix:/tmp/.X11-unix")
fi
if [ "$map_host" = true ]; then
extra_args+=("-v" "/:/host/")
fi
if [[ ! -z $userstring ]]; then
userstringsplit=(${userstring//:/ })
new_username=${userstringsplit[0]}
extra_args+=("-e" "USERSTRING=$userstring")
if [[ ! -z $home_folder ]]; then
if [[ $home_folder == *":"* ]]; then
extra_args+=("-e" "SSHFSDIRS=\"$home_folder;/home/$new_username/\"")
else
home_folder_full=$(readlink -f $home_folder || echo "") >/dev/null 2>&1
if [[ ! -z $home_folder_full ]]; then
home_folder=$home_folder_full
fi
if [[ "$new_username" == "root" ]]; then
extra_args+=("-v" "$home_folder:/root/")
else
extra_args+=("-v" "$home_folder:/home/$new_username/")
fi
fi
fi
fi
if [[ ! -z $working_folder ]]; then
extra_args+=("-e" "WORKINGFOLDER=$working_folder")
fi
if [ "$use_tmux" = true ]; then
detach_tmux="$detach_container"
detach_container=true
fi
if [ "$detach_container" = true ]; then
extra_args+=("-d")
else
extra_args+=("-it")
fi
if [ "$use_nvidia_runtime" = true ]; then
if [ "$use_gpus_all" = true ]; then
extra_args+=("--gpus=all")
else
extra_args+=("--runtime=nvidia")
fi
fi
if [ "$pass_ssh_key" = true ]; then
ssh_key=`cat $HOME/.ssh/id_rsa.mldock`
ssh_key="${ssh_key//$'\n'/ }"
extra_args+=("-e" "SSHKEY=\"$ssh_key\"")
fi
cmd+=("docker" "run" \
"-e" "SSHPORT=9022" \
"--rm" \
"--privileged" \
"--shm-size=32gb" \
"--network=host")
if [[ ! -z "$container_name" ]]; then
cmd+=( "--name=$container_name" )
fi
cmd+=( "${extra_args[@]}" )
cmd+=( "$repository$image_name:$version_name" )
if [ "$use_tmux" = true ]; then
cmd+=("run_in_detached_tmux")
fi
if [[ ! -z "$command_to_run" ]]; then
cmd+=( "${command_to_run[@]}" )
fi
}
run_command() {
if [ "$print_command" = true ]; then
echo "Running: ${docker_sudo_prefix}${cmd[@]}"
echo ""
fi
"${docker_sudo_prefix}${cmd[@]}"
if [ "$use_tmux" = true ] && [[ "$detach_tmux" = false ]]; then
new_username=$(${docker_sudo_prefix}docker exec $container_name cat /tmp/dock_config/username)
${docker_sudo_prefix}docker exec -it -u $new_username $container_name tmux a
fi
}
run_remote_command() {
if [ "$print_command" = true ]; then
echo "Running on $remote_ip: ${cmd[@]}"
echo ""
fi
ssh $remote_ip -t "${cmd[@]}"
if [ "$use_tmux" = true ] && [[ "$detach_tmux" = false ]]; then
new_username=$(ssh $remote_ip -t docker exec $container_name cat /tmp/dock_config/username)
ssh $remote_ip -t docker exec -it -u $new_username $container_name tmux a
fi
}
gen_exec_command() {
folder_exists=$(docker exec -w $working_folder mldock_omeryair echo test >& /dev/null && echo true || echo false)
new_username=$(${docker_sudo_prefix}docker exec $container_name cat /tmp/dock_config/username)
if [[ ! -z "$new_username" ]]; then
extra_args+=("-u" "$new_username")
fi
if [ "$folder_exists" = true ]; then
extra_args+=("-w" "$working_folder")
else
if [[ ! -z "$new_username" ]]; then
extra_args+=("-w" "/home/$new_username")
fi
fi
cmd+=("docker" "exec" \
"-it")
cmd+=( "${extra_args[@]}" )
cmd+=( "$container_name" )
cmd+=( "${command_to_run[@]}" )
}
stop_container() {
echo "-> Stopping the container"
${docker_sudo_prefix}docker stop $container_name
}
main_cli "$@"