Skip to content
vanpeerdevelopment edited this page Jan 15, 2016 · 3 revisions

Links are deprecated

Container linking used to be the way to make interactions between different containers possible. When containers are linked several environment variables are created exposing information such as the IP address and exposed ports of the linked container. Besides these environment variables an entry in the hosts file is also added to map the name of the linked container to an IP address. This information can then be used to connect to linked containers. Container linking is now deprecated and the way to go nowadays is to create networks and run containers that need to communicate in the same network.

Networks

Two different types of networks are supported: overlay and bridge networks.Overlay networks make it possible to create networks over several docker hosts. Bridge networks can be used to create networks within one host.

On user defined networks each container will have a mapping in its hosts file for each container on that network. This way it is possible to communicate with another container on the same network using its name. Ports which are exposed in the Dockerfile are also accessible by other containers on the same network without having to publish them on the host. If a port needs to be accessible externally it is still required to publish it on the host. Container linking is not supported on user defined networks.

Default bridge network

The default bridge network is kind of a special network. It is the only network that still supports container linking. But all the features of user defined networks are not applicable to the default bridge network.

Example

Docker Bridge Network

The network above can be created with the following commands:

(1) docker network create -d bridge dws-prd
(2) docker run -d --net dws-prd --name database dws/db
(3) docker run -d --net dws-prd --name backend 
    --env db.host=database:5432 dws/back-end
(4) docker run -d --net dws-prd --name frontend -p 80:80 
    --env dws_api_proxy=backend:8080 dws/front-end