@@ -8,6 +8,7 @@ verbose=false
8
8
arch=" ` arch` "
9
9
tag=
10
10
platform=
11
+ container=
11
12
while test " $# " -ne 0; do
12
13
if test " $1 " = " -f" -o " $1 " = " --fresh" ; then
13
14
fresh=1
@@ -26,12 +27,18 @@ while test "$#" -ne 0; do
26
27
elif test " $1 " = " -x" -o " $1 " = " --x86-64" -o " $1 " = " --x86_64" -o " $1 " = " --amd64" ; then
27
28
platform=linux/amd64
28
29
shift
30
+ elif test " (" " $1 " = " -t" -o " $1 " = " --tag" " )" -a " $# " -gt 1; then
31
+ tag=" $2 "
32
+ shift 2
33
+ elif test -z " $container " -a -z " $fresh " -a -n " $1 " && expr " $1 " : ' [0-9a-f][0-9a-f][0-9a-f]*$' > /dev/null 2>&1 ; then
34
+ container=" $1 "
35
+ shift
29
36
else
30
37
armtext=
31
38
if test " $arch " = " arm64" -o " $arch " = " aarch64" ; then
32
39
armtext=" [-a|--arm] [-x|--x86-64]"
33
40
fi
34
- echo " Usage: cs61-run-docker [-f|--fresh]$armtext [-V|--verbose]" 1>&2
41
+ echo " Usage: cs61-run-docker [-f|--fresh]$armtext [-V|--verbose] [CONTAINERID] " 1>&2
35
42
exit 1
36
43
fi
37
44
done
61
68
fi
62
69
myfileid=` stat $statformatarg %d:%i " ${BASH_SOURCE[0]} " 2> /dev/null`
63
70
71
+ ssharg=
72
+ sshenvarg=
73
+ if test -n " $SSH_AUTH_SOCK " -a " ` uname` " = Darwin; then
74
+ ssharg=" --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock"
75
+ sshenvarg=" -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock"
76
+ fi
77
+
64
78
dir=" ` pwd` "
65
79
subdir=" "
66
80
while test " $dir " ! = / -a " $dir " ! = " " ; do
@@ -78,24 +92,31 @@ if test -z "$maindir" && expr "${BASH_SOURCE[0]}" : / >/dev/null 2>&1; then
78
92
subdir=" "
79
93
fi
80
94
81
- ssharg=
82
- sshenvarg=
83
- if test -n " $SSH_AUTH_SOCK " -a " ` uname` " = Darwin; then
84
- ssharg=" --mount type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock"
85
- sshenvarg=" -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock"
86
- fi
87
-
88
- if test -n " $maindir " -a -z " $fresh " ; then
89
- existing_image=" ` docker ps -f status=running -f ancestor=$tag -f volume=/host_mnt" $maindir " --no-trunc --format " {{.CreatedAt}},{{.ID}}" | sort -r | head -n 1` "
90
- if test -n " $existing_image " ; then
91
- created_at=" ` echo $existing_image | sed ' s/,.*//' ` "
92
- image=" ` echo $existing_image | sed ' s/^.*,//' ` "
93
- image12=" ` echo $image | head -c 12` "
94
- echo " * Using running container $image12 , created $created_at " 1>&2
95
- echo " - To start a new container, exit then \` cs61-run-docker -f\` " 1>&2
96
- echo " - To kill this container, exit then \` docker kill $image12 \` " 1>&2
97
- vexec docker exec -it$sshenvarg $image /bin/bash
95
+ existing_image=" "
96
+ if test -n " $container " ; then
97
+ existing_image=" ` docker ps -f " id=$container " --no-trunc --format " {{.CreatedAt}},{{.ID}}" | sort -r | head -n 1` "
98
+ if test -z " $existing_image " ; then
99
+ echo " * Container $container not found" 1>&2
100
+ echo " - To start a new container, try \` cs61-run-docker -f\` " 1>&2
101
+ echo " - To list executing containers, try \` docker ps\` " 1>&2
102
+ exit 1
103
+ elif test " ` echo " $existing_image " | wc -l` " -gt 1; then
104
+ echo " * Container $container ambiguous" 1>&2
105
+ echo " - To start a new container, try \` cs61-run-docker -f\` " 1>&2
106
+ echo " - To list executing containers, try \` docker ps\` " 1>&2
107
+ exit 1
98
108
fi
109
+ elif test -n " $maindir " -a -z " $fresh " ; then
110
+ existing_image=" ` docker ps -f status=running -f ancestor=$tag -f volume=/host_mnt" $maindir " --no-trunc --format " {{.CreatedAt}},{{.ID}}" | sort -r | head -n 1` "
111
+ fi
112
+ if test -n " $existing_image " ; then
113
+ created_at=" ` echo $existing_image | sed ' s/,.*//' ` "
114
+ image=" ` echo $existing_image | sed ' s/^.*,//' ` "
115
+ image12=" ` echo $image | head -c 12` "
116
+ echo " * Using running container $image12 , created $created_at " 1>&2
117
+ echo " - To start a new container, exit then \` cs61-run-docker -f\` " 1>&2
118
+ echo " - To kill this container, exit then \` docker kill $image12 \` " 1>&2
119
+ vexec docker exec -it$sshenvarg $image /bin/bash
99
120
fi
100
121
101
122
netarg=
0 commit comments