I have two existing docker container web and db. I want to link these two container, so that they will communicate with each other. If i go with --link command means it will link web to a new image and not to the db.
Using --link
was the only way of connecting containers before the advent of docker networks. These provide a "cleaner" solution to the problem of inter-container communication and at the same time solves 2 of the major limits of links:
Using docker network you would use the --net
option to start the containers on the specified network:
docker network create example
docker run -d --net example --name container1 <image>
docker run -d --net example --name container2 <image>
At this point the 2 container are mutually reachable via the address <container-name>.example
: that is container1.example
and container2.example
.