-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker.sh
executable file
·145 lines (139 loc) · 4.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
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
#!/usr/bin/env bash
if [ $# -eq 0 ]
then
echo "Usage:"
echo
echo " `basename $0` (u | up) [<containers>] Create and start"
echo " `basename $0` (p | pull) [<containers>] pull containers"
echo " `basename $0` (U | uppull) [<containers>] Create and start (force pull)"
echo " `basename $0` (d | down) [<containers>] Stop and remove"
echo " `basename $0` (s | start) [<containers>] Start"
echo " `basename $0` (r | restart) [<containers>] Restart"
echo " `basename $0` (h | stop) [<containers>] Stop (halt)"
echo " `basename $0` (i | install) [<containers>] Autorestart running containers on failure/reboot"
echo " `basename $0` ps [<containers>] List"
echo " `basename $0` rm [<containers>] Remove"
echo " `basename $0` stats Show statistics"
echo
echo " `basename $0` (l | log) <container> Show log tail (last 100 lines)"
echo " `basename $0` (e | exec) <container> <command> Execute command"
echo " `basename $0` (a | attach) <container> Attach to container with shell"
echo
echo " `basename $0` prune Remove all unused containers, networks and images"
echo " `basename $0` stopall Stop all running containers (system-wide!)"
echo " `basename $0` killall Kill all running containers (system-wide!)"
echo
echo "Arguments:"
echo
echo " containers One or more containers (omit to affect all containers)"
echo " container Excactly one container to be affected"
echo " command Command to be executed inside a container"
exit
fi
os=`uname`
case $os in
Linux)
# Check if on Jetson platform
if [ -f /etc/nv_tegra_release ]; then
# Extract the R number
r_number=$(grep -oP 'R\d+' /etc/nv_tegra_release)
case $r_number in
R35)
# Jetson Orin
compose_args="$compose_args -f docker-compose.yml -f docker-compose.jetson.orin.yml"
;;
R32)
# Jetson Nano
compose_args="$compose_args -f docker-compose.yml -f docker-compose.jetson.yml"
;;
*)
echo "Unsupported Jetson version: $r_number"
exit 1
;;
esac
fi
# Check if an Nvidia GPU is available
( nvidia-smi > /dev/null 2>&1 ) && compose_args="$compose_args -f docker-compose.yml -f docker-compose.nvidia.yml"
;;
Darwin)
compose_args="$compose_args -f docker-compose.yml -f docker-compose.mac.yml"
;;
*)
echo "Unsupported OS: $os"
exit 1
esac
export DOCKER_BUILDKIT=1
if [ -d /usr/local/zed ]; then
if [ -d ../zedxmini ]; then
compose_args="$compose_args -f docker-compose.jetson.orin.zedxmini.yml"
else
echo -e "\033[33mWARNING:\033[0m Zed X Mini not found. https://github.com/zauberzeug/zedxmini"
fi
fi
cmd=$1
cmd_args=${@:2}
set -x
case $cmd in
b | build)
docker-compose $compose_args pull detector
docker-compose $compose_args build --no-cache $cmd_args
;;
u | up)
docker-compose $compose_args up -d $cmd_args
;;
p | pull)
docker-compose $compose_args pull
;;
U | uppull)
docker-compose $compose_args pull
docker-compose $compose_args up -d --build $cmd_args
;;
d | down)
docker-compose $compose_args down -d $cmd_args
;;
s | start)
docker-compose $compose_args start $cmd_args
;;
r | restart)
docker-compose $compose_args restart $cmd_args
;;
h | stop)
docker-compose $compose_args stop $cmd_args
;;
i | install)
echo "disabing restart for any containers which may have been configured before"
docker update --restart=no $(docker ps -a -q) > /dev/null
echo "configuring running containers to always restart"
docker update --restart=always $(docker ps -q)
;;
rm)
docker-compose $compose_args rm $cmd_args
;;
ps)
docker-compose $compose_args ps $cmd_args
;;
stat | stats)
docker stats $cmd_args
;;
l | log | logs)
docker-compose $compose_args logs -f --tail 1000 $cmd_args
;;
e | exec)
docker-compose $compose_args exec $cmd_args
;;
a | attach)
docker-compose $compose_args exec $cmd_args /bin/bash
;;
prune)
docker system prune
;;
stopall)
docker stop $(docker ps -aq)
;;
killall)
docker kill $(docker ps -aq)
;;
*)
echo "Unsupported command \"$cmd\""
exit 1
esac