When inter container communication (icc) is enabled with Docker, containers on the same host can be linked together to work as unit.
Let's say we want to build app which requires a Database and Web server, we can :-
- put both of them in one container
- put them a different container but on same system
- put them on different systems in different systems, in the same cluster
In this recipe, we will look how we can link diffent container on the same system
$ vagrant ssh labvm-1
$ sudo -s
$ docker run -d -e MYSQL_ROOT_PASSWORD=my-secret-pw --name=db mysql
$ docker inspect --format='' db
$ docker run -itd --name web --link db:database centos
$ docker ps
$ docker inspect -f "" web
$ docker exec -it web bash
$ ip a
$ cat /etc/hosts
$ env
$ ping $DATABASE_PORT_3306_TCP_ADDR