-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.sh
executable file
·79 lines (76 loc) · 1.8 KB
/
docker.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
#!/bin/bash
#set -x
dry_run=0
interactive=0
grep_value=
command=
it=" -it"
USER=${USER:-$(whoami)}
image=${USER}_vllm
suffix=
name=${USER}_vllm
while : ; do
docker ps --format "{{.Names}}" | grep $name$suffix &> /dev/null || break
suffix=$(( suffix + 1 ))
done
name=$name$suffix
while [[ $# -gt 0 ]] ; do
i=$1
case $i in
-n|--name)
name="$2"
shift
;;
-d|--dry=run)
dry_run=1
;;
-g|--grep)
grep_value="$2"
shift
;;
-i|--interactive)
interactive=1
;;
--noit)
it=
;;
-c|--command)
command="$2"
shift
;;
*)
image=$1
;;
esac
shift
done
if [[ $interactive == 1 ]] ; then
grep_arg=
if [[ $grep_value != "" ]] ; then
grep_arg=" | grep $grep_value"
fi
cmd="docker images | awk '{print \$1 \":\" \$2}' | grep -v none | grep -v REPOSITORY:TAG $grep_arg"
images=$(eval $cmd)
i=0
for im in $images ; do
echo "$i $im"
i=$((i+1))
done
read -p "Select image: " selection
images_arr=($images)
image=${images_arr[$selection]}
read -p "Container name: " name
fi
echo "Image: $image"
name_arg=
if [[ $name != "" ]] ; then
name_arg=" --name $name"
fi
if [[ $dry_run != 1 ]] ; then
tmux rename-window "Docker:$name"
docker run ${it} --rm --device=/dev/kfd --device=/dev/dri --mount type=bind,source=/home/gshtrasb/Projects,target=/projects --mount type=bind,source=/data/models,target=/models --ulimit core=0:0 --group-add video --cap-add=SYS_PTRACE $name_arg $image $command
tmux setw automatic-rename on
echo "Finished docker image $image"
else
echo "docker run ${it} --rm --device=/dev/kfd --device=/dev/dri --mount type=bind,source=/home/gshtrasb/Projects,target=/projects --mount type=bind,source=/data/models,target=/models --ulimit core=0:0 --group-add video --cap-add=SYS_PTRACE $name_arg $image" $command
fi