I have two containers one link to another. As the following...
docker run -i -t --name container1 ubuntu:trusty
docker run -i -t --name container2 --link container1:aliasc1 ubuntu:trusty /bin/bash
is there a simple way to obtain ip of container1 from container2 using link alias aliasc1?
I orchestrate container using docker-compose
Docker will create an entry in /etc/host for the containers linked. So you can get that ip from there. I.e.:
cat /etc/hosts | grep aliasc1 | awk {'print $1'}
Docker automatically creates environment variables for this purpose. For example if container1 exposes port 80, then container2 will have $ALIASC1_PORT_80_TCP_ADDR defined.
See http://docs.docker.com/userguide/dockerlinks/#environment-variables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With