Created
October 30, 2022 16:23
-
-
Save gmariette/7f44ac4a2f80d1e4e5663ce7f4e32fd4 to your computer and use it in GitHub Desktop.
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
IdentifyDockerPorts(){ | |
FuncName | |
export PORT_LIST="" | |
OLDIFS=${IFS} | |
IFS=$'\n' | |
for CONTAINER in $(docker ps -q); do | |
if [[ ${PORT_LIST} == "" ]]; then | |
PORT_LIST=$(docker inspect ${CONTAINER} | jq -r '.[].HostConfig.PortBindings| .[]| .[]|.HostPort') | |
else | |
PORT_LIST=$(echo ${PORT_LIST},$(docker inspect ${CONTAINER} | jq -r '.[].HostConfig.PortBindings| .[]| .[]|.HostPort')) | |
fi | |
done | |
echo "Identified ports ${PORT_LIST}" | |
IFS=${OLDIFS} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment