Skip to content

Instantly share code, notes, and snippets.

@AndrewPaglusch
Last active October 8, 2021 23:53
Show Gist options
  • Select an option

  • Save AndrewPaglusch/7176f636918b08d820688e4fa03f7bc5 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewPaglusch/7176f636918b08d820688e4fa03f7bc5 to your computer and use it in GitHub Desktop.
Find the Host "veth" Interface Each Running Docker Container is Using
# This script will tell you what Docker container is tied to which vethXXXXXXXX interface on the host
# All other "solutions" to this problem that I found require you to exec into the container
#!/bin/bash
{ echo -e "CONTAINER_NAME\tPID\tINTERFACE"
docker ps --format '{{.Names}}' | while read cname; do
PID="$(docker inspect --format="{{.State.Pid}}" "${cname}")"
INTERFACE="$(ip link show | grep -P "^$(nsenter -t "${PID}" -n ip link show eth0 | grep -oP '(?<=@if)[^:]+')(?=:)" | grep -oP 'veth[^@]+')"
echo -e "${cname}\t${PID}\t${INTERFACE}"
done } | column -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment