I created a Droplet on DigitalOcean using Docker machine.
When running two containers and linking them this way from Jenkins:
/bin/bash/eval "$(docker-machine env deployment)"
/bin/bash -c "docker run -d -t --name container1 -p 5000:5000 image1"
/bin/bash -c "docker run -d -t --name container2 -p 5001:5001 --link container1:container1 image2"
And then docker inspect container1 | grep "IPAddress" I get 172.17.0.51.
But when I run the Node.js application in container2 which calls process.env.CONTAINER1_PORT_5000_TCP_ADDR it resolves to
172.17.0.7:5000 when I call container2 from its public IP (of the DO droplet) which causes to return No route to host.
When I exec into container2 and run node process.env.CONTAINER1_PORT_5000_TCP_ADDR it returns 172.17.0.51.
If I ssh into the host using another user, docker inspect container2 | grep "IPAddress" also returns 172.17.0.52 instead of 172.17.0.51.
Why does the Node.js application return the wrong IP address whereas running Node.js on the command line returns a different and correct IP address?
Update: If I run the containers locally on the Jenkins machine without docker-machine and DO, everything works fine.