Skip to main content

Network (Draft version)

When a docker container starts it will start in some network environment based on given inputs, by default it will take private virtual network of docker "bridge" All containers in a virtual network can talk to each other and we expose required containers by routing through NAT firewall on host IP. It is possible to add one container to multiple virtual networks, or we can even initalize container without adding to any virtual network. Or even it is possible to use direct host network by using --net=host

It is possible to use different docker network drivers which will provide new abilities to network. The container will run on its own ip address

When creating containers and attach them to some network based on order of initialization, host network or environment different ip address will assigned to it. But to solve this problem docker network will provide host names to these container ips which are same as container names. And it is also possible to assign an alias host name using --net-alias property This feature is helpful when we want to run multiple instances of same application / server and do load balancing with different load balance algorithm. When we have to communicate internally with different servers we use host name. This DNS system by default not available on default docker network the 'bridge'. It is always recommended run containers on custom networks.

docker network ls # Shows all available docker private networks

docker network inspect <network name>
docker network inspect my-network

docker network create <network name> --driver # The --driver is optional by default there would host, bridge and none etc. can be used in place of driver.

docker network connect <container> <network>

docker network disconnect <container> <network>

docker container run -d --net <network> --net-alias <alias> # This will connects container `network` to given network and use `alias` as its hostname.