-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.1m.sh
More file actions
executable file
·82 lines (74 loc) · 2.69 KB
/
docker.1m.sh
File metadata and controls
executable file
·82 lines (74 loc) · 2.69 KB
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
export PATH="/usr/local/bin:/usr/bin:$PATH"
echo "⚓️ | dropdown=false"
echo "---"
function containers() {
CONTAINERS="$(docker ps -a --format "{{.Names}} ({{.Image}})|{{.ID}}|{{.Status}}")"
if [ -z "$CONTAINERS" ]; then
echo "No running containers"
else
LAST_CONTAINER=$(echo "$CONTAINERS" | tail -n1 )
echo "${CONTAINERS}" | while read -r CONTAINER; do
CONTAINER_NAME=$(echo "$CONTAINER" | awk -F"|" '{print $1}')
CONTAINER_ID=$(echo "$CONTAINER" | awk -F"|" '{print $2}')
CONTAINER_STATE=$(echo "$CONTAINER" | awk -F"|" '{print $3}')
SYM="├ 💻 "
if [ "$CONTAINER" = "$LAST_CONTAINER" ]; then SYM="└ 💻 "; fi
case "$CONTAINER_STATE" in
*Up*) echo "$SYM $CONTAINER_NAME | color=green bash=\"$(command -v docker)\" param1=stop param2=$CONTAINER_ID terminal=false refresh=true";;
*Exited*) echo "$SYM $CONTAINER_NAME | color=red bash=\"$(command -v docker)\" param1=start param2=$CONTAINER_ID terminal=false refresh=true";;
esac
done
fi
}
if command -v docker-machine > /dev/null; then
DOCKER_MACHINES="$(docker-machine ls -q)"
fi
if command -v dlite > /dev/null; then
DLITE="$(command -v dlite)"
fi
if command -v docker > /dev/null; then
DOCKER_NATIVE="$(command -v docker)"
fi
if test -z "$DOCKER_MACHINES" && test -z "$DLITE" && test -z "$DOCKER_NATIVE"; then
echo "No docker machine, dlite or docker native found"
exit 0
fi
if [ -n "$DOCKER_NATIVE" ]; then
MACHINE="$($DOCKER_NATIVE -v)"
CONTAINERS="$($DOCKER_NATIVE ps -a --format "{{.Names}} ({{.Image}})|{{.ID}}|{{.Status}}")"
if [ -n "$CONTAINERS" ]; then
echo "🔵 $MACHINE | bash=\"$DOCKER_NATIVE\" param1=stop terminal=false refresh=true"
containers
fi
exit 0
fi
if [ -n "$DLITE" ]; then
MACHINE="$($DLITE ip)"
CONTAINERS="$(docker ps -a --format "{{.Names}} ({{.Image}})|{{.ID}}|{{.Status}}")"
if [ -z "$CONTAINERS" ]; then
echo "🔴 $MACHINE | bash=\"$DLITE\" param1=start terminal=false refresh=true"
else
echo "🔵 $MACHINE | bash=\"$DLITE\" param1=stop terminal=false refresh=true"
containers
fi
exit 0
fi
if [ -n "$DOCKER_MACHINES" ]; then
DM_EXEC=$(command -v docker-machine)
echo "${DOCKER_MACHINES}" | while read -r machine; do
STATUS=$($DM_EXEC status "$machine")
if [ "$STATUS" = "Running" ]; then
echo "🔵 $machine | bash=\"$DM_EXEC\" param1=stop param2=$machine terminal=false refresh=true"
ENV=$($DM_EXEC env --shell sh "$machine")
eval "$ENV"
containers
else
echo "🔴 $machine | bash=\"$DM_EXEC\" param1=start param2=$machine terminal=false refresh=true"
fi
echo "---"
done
fi
if [ -n "$CONTAINERS" ]; then
echo "Docker VM Containers"
containers
fi