Skip to content

Instantly share code, notes, and snippets.

@martijngastkemper
Last active March 20, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijngastkemper/a9aff8968fe6a790ea08e528d248f008 to your computer and use it in GitHub Desktop.
Save martijngastkemper/a9aff8968fe6a790ea08e528d248f008 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Usage: bash list-ports.sh PRIVATE_PORT
# PRIVATE_PORT default 80
privatePort=${1-80}
services=`docker-compose ps --service --filter "status=running" 2> /dev/null`
if [ -z "$services" ]
then
echo "❗️no running services found" >&2
exit 1
fi
echo Private port $privatePort
for service in $services
do
port=`docker-compose port $service $privatePort 2> /dev/null`
if [ $? -eq 0 ] && [ -n "$port" ]
then
echo $service: $port
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment