Given a docker machine (started with docker-machine
) and a docker-compose.yml
file with a service (ex: web) that exposes a port (ex: 3000), get the address for a running container, ex:
$ addr web 3000
192.168.99.100:32768
If not running from directory containing docker-compose.yml
, or if you want to use an alternative .yml
file, specify the file pathname with the 3rd parameter, ex:
$ addr web 3000 path/to/common.yml
192.168.99.100:32768
Add this function to your .bashrc
file:
function addr {
service=$1
containerport=$2
file=${3:-"docker-compose.yml"}
echo $(docker-machine ip $(docker-machine active)):$(docker-compose -f $file port $service $containerport | cut -d ':' -f 2)
}