-
-
Save oskapt/d041d4f5d0d87c221096bc0cc3416e70 to your computer and use it in GitHub Desktop.
Revisions
-
superseb created this gist
Jan 29, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/bin/bash # Based on https://github.com/moby/moby/issues/17064#issuecomment-294020260, thanks! function cali_interface_for_container() { container_name=$(docker inspect --format='{{.Name}}' "${1}") # Get the process ID for the container named ${1}: local pid=$(docker inspect -f '{{.State.Pid}}' "${1}") # Make the container's network namespace available to the ip-netns command: mkdir -p /var/run/netns ln -sf /proc/$pid/ns/net "/var/run/netns/${1}" # Get the interface index of the container's eth0: local podip=$(ip netns exec $1 ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) local index=$(ip netns exec $1 ethtool -S eth0 2>/dev/null | grep peer_ifindex | awk '{ print $2 }') local mac=$(ip netns exec $1 ip addr show eth0 | grep ether | awk '{ print $2 }') # Write the name of the veth interface to stdout: VETH=$(ip link show | grep "^${index}:" | awk '{ print $2 }') echo "$1 $container_name $(echo $podip) $mac $VETH $index" # Clean up the netns symlink, since we don't need it anymore rm -f "/var/run/netns/${1}" } if [ "$#" -eq 0 ]; then for docker_container in `docker ps -q --filter=name=POD`; do cali_interface_for_container $docker_container done fi if [ "$#" -eq 1 ]; then cali_interface_for_container $1 fi