Last active
August 11, 2021 05:14
-
-
Save devopsy-ir/b551101415ed43bde082859e68cb5f26 to your computer and use it in GitHub Desktop.
Convert port number into the container name and IP
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
#!/bin/bash | |
docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /' | fgrep $(iptables-save | grep -P "(--to-destination|--.port)" | grep -v "DROP" | grep -P ":\d+|--dport \d+" | fgrep $1 | fgrep -i docker | egrep "to-destination" | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run by: port-to-container