Container and container communicate with each other. The official name is linking containers together!
The most common is to run a web iner and a DB container to link the Web container to the DB container;
A network channel (BRIDGE) is established between two containers through link, and DB iner only needs to know the alias and open port number of the previous container;
Example:
Start a DB container first:
$ sudo docker run -d --name db training/postgres
Then start Web Container link dB container
$ sudo docker run -d -P --name web --link db:db training/webapp python app.py
Note -- Link flag takes the form:
--link name:alias
View through docker PS:
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES349169744e49 training/postgres:latest su postgres -c ‘/usr About a minute ago Up About a minute 5432/tcp db, web/dbaed84ee21bde training/webapp:latest python app.py 16 hours ago Up 2 minutes 0.0.0.0:49154->5000/tcp web
The DB container Web/DB shows that the Web container has been linked to the DB container.
This article is from the "Siberian wolf" blog, please be sure to keep this source http://kernal.blog.51cto.com/8136890/1538610