UPDATE:
As of Docker 1.3 (or probably even from earlier version, not sure), the /etc/hosts
file will be updated with the new ip of a linked containers if it restarts. This means that if you access it via its name within the /etc/hosts
entry as opposed to the environment variable, your link will still work even after restart.
Example:
When you starts two containers app_image
and mysql
and link them like this:
$ docker run --name mysql mysql:5.6.20
$ docker run -d --link mysql:mysql app_image
you'll get an entry in your /etc/hosts
within app_image
:
# /etc/hosts example
mysql 172.17.0.12
and that ip will be refreshed in case mysql
crashes and is restarted.
So don't use environment variables when referring to your linked container:
$ ping $MYSQL_PORT_3306_TCP_ADDR # --> don't use! won't work after the linked container restarts
$ ping mysql # --> instead, access it by the name as in /etc/hosts
Old answer:
Nope,it won't. In the face of crashing containers scenario, links are as good as dead. I think it is pretty much an open problem,i.e., there are many candidate solutions, but none are yet to be crowned the standard approach.
You might want to take a look at http://jasonwilder.com/blog/2014/07/15/docker-service-discovery/