-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-netshoot
executable file
·52 lines (45 loc) · 1006 Bytes
/
docker-netshoot
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
#!/bin/bash
set -euo pipefail
NETSHOOT_IMAGE="nicolaka/netshoot"
usage() {
echo "Run netshoot container with docker network."
echo "Options:"
printf "\t%s\t\t%s\n" "-h" "print this help"
printf "\t%s\t%s\n" "-n NETWORK" "user provided network"
printf "\t%s\t\t%s\n" "-N" "user default network"
}
select_network() {
docker network ls | fzf \
--header-lines=1 \
--select-1 --exit-0 \
--preview-label="Containers" \
--preview-window=down,10 \
--preview "docker network inspect {1} | jq -r '.[].Containers | .[].Name'" | awk '{print $1}'
}
main() {
local network=
while getopts "hNn:" opt; do
case "${opt}" in
h)
usage
exit
;;
N)
network="default"
;;
n)
network="$OPTARG"
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ -z "$network" ]; then
network=$(select_network)
fi
docker run --interactive --tty --rm --network "$network" "$NETSHOOT_IMAGE"
}
main "$@"