The docker --link
argument, and link:
sections docker-compose make aliases to other containers.
docker network create sample
docker run -d --net sample --name redis redis
With link either the original name or the mapping will resolve the redis container.
> docker run --net sample --link redis:cache -ti python:alpine sh -c "pip install redis && python"
>>> import redis
>>> r = redis.StrictRedis(host='cache')
>>> r.set('key', 'value')
True
Before docker 1.10.0
container linking also setup network connectivity - behavior now provided by docker network. Links in later versions only provide legacy
effect on the default bridge network.