Skip to content

Instantly share code, notes, and snippets.

@gmariette
Created October 30, 2022 16:23
Show Gist options
  • Save gmariette/7f44ac4a2f80d1e4e5663ce7f4e32fd4 to your computer and use it in GitHub Desktop.
Save gmariette/7f44ac4a2f80d1e4e5663ce7f4e32fd4 to your computer and use it in GitHub Desktop.
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