Last active
October 8, 2021 23:53
-
-
Save AndrewPaglusch/7176f636918b08d820688e4fa03f7bc5 to your computer and use it in GitHub Desktop.
Find the Host "veth" Interface Each Running Docker Container is Using
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 characters
| # 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