Moved docker-iptables and docker-ports to docker-cli-tools

master
gdm85 9 years ago
parent 2a797d8323
commit b81fb3ac93

@ -1,28 +0,0 @@
#!/bin/bash
## docker-iptables
##
## @author gdm85
## script to show iptables rules with docker names
## can be used also to detect problems with dead containers and stale iptable rules
## supports standard iptables-save syntax
#
function replace_iptables() {
local CID
local SEDCMD="-e s!172.17.42.1/32!dockerHost!g
for CID in $(docker ps -q -a); do
local NAME=$(docker inspect --format '{{ .Name }}' $CID | awk '{ print substr($0, 2, length($0)-1) }')
local IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CID)
if [ -z "$IP" ]; then
continue
fi
SEDCMD="$SEDCMD -e s!$IP/32!${NAME}!g -e s!$IP!${NAME}!g"
done
sed $SEDCMD
}
iptables-save $@ | replace_iptables

@ -1,62 +0,0 @@
#!/bin/bash
## docker-ports
##
## @author gdm85
## script to show docker allocated ports of a container
#
if ! type jq >/dev/null 2>/dev/null; then
echo "jq must be installed" 1>&2
exit 1
fi
if [ $# -lt 1 ]; then
echo "Please specify at least one container" 1>&2
exit 1
fi
function show_ports() {
local CID="$1"
local CONTAINER_IPv4=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CID) || return $?
if [[ -z "$CONTAINER_IPv4" || "$CONTAINER_IPv4" == "<no value>" ]]; then
echo "Invalid container: $CID" 1>&2
return 1
fi
local NAME=$(docker inspect --format '{{ .Name }}' $CID | awk '{ print substr($0, 2, length($0)-1) }')
local STANZA="$(docker inspect --format '{{json .HostConfig.PortBindings }}' $CID)" || return $?
echo "$NAME:"
let I=0
for P in $(echo "$STANZA" | jq -M 'keys' | tail -n+2 | head -n-1 | sed s/,$// | sed 's/"//g' ); do
## port on container
local SRCPORT="$(echo $P | awk -F/ '{ print $1 }')"
echo -e -n "\t$SRCPORT\t<-\t"
## get port binding (if any)
local SNIP=$(echo $STANZA | jq -M "to_entries | .[$I].value")
if [[ -z "$SNIP" || "$SNIP" == "null" ]]; then
echo "$CONTAINER_IPv4:$SRCPORT"
else
local HOSTIP="$(echo $SNIP | jq -M -r '.[0].HostIp')"
## match only bindings on dockerhost
if [[ -z "$HOSTIP" || "$HOSTIP" == '0.0.0.0' ]]; then
local HOSTPORT="$(echo $SNIP | jq -M -r '.[0].HostPort')"
echo "0.0.0.0:$HOSTPORT"
else
echo "$HOSTIP:$SRCPORT"
fi
fi
let I=I+1
done
}
for CID in $@; do
show_ports "$CID"
done
Loading…
Cancel
Save