From b81fb3ac93d361057b23a45bb83d270601dbc421 Mon Sep 17 00:00:00 2001 From: gdm85 Date: Tue, 20 Jan 2015 13:07:25 +0100 Subject: [PATCH] Moved docker-iptables and docker-ports to docker-cli-tools --- docker/scripts/docker-iptables | 28 --------------- docker/scripts/docker-ports | 62 ---------------------------------- 2 files changed, 90 deletions(-) delete mode 100755 docker/scripts/docker-iptables delete mode 100755 docker/scripts/docker-ports diff --git a/docker/scripts/docker-iptables b/docker/scripts/docker-iptables deleted file mode 100755 index fe23c0a..0000000 --- a/docker/scripts/docker-iptables +++ /dev/null @@ -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 diff --git a/docker/scripts/docker-ports b/docker/scripts/docker-ports deleted file mode 100755 index bd047ef..0000000 --- a/docker/scripts/docker-ports +++ /dev/null @@ -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" == "" ]]; 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