Table of contents
Networking is all about communications. How systems talk to one another and share files and information with other systems within a close and distant range.
Docker technology also has its unique way of networking within its own space. Containers and services must not be aware of their hosting OS or deployment environment or be within the same environment before they can talk to each other.
Networking in docker utilizes multiple layers of the network, these layers intertwined with each of them serving a peculiar cause.
Docker Network Types
- Bridge
Each running container in Docker is linked to a virtual network known as a bridge. A bridge is a prominent network driver in Docker because they are easy to configure, administer, and debug.
The bridge network employs a program that enables containers to connect to the network and communicate. It solves the problem of containers that are not authorised to connect by establishing networking rules on host machines that prevent containers from communicating directly with each other.
If there are no ports given, containers in the same bridge network can communicate with one another and if there is no network assigned, containers can use the bridge network by default.
- Host
The host network drivers make use of the network generated by the host server other than the network provided by docker to maintain network connectivity between the container and the host machine. Though the host driver is limited to Linux host machines, it is quite easy to set up and troubleshoot.
Other Network types
Overlay driver: for containers across the host to communicate with one another without having to bother about configuration.
Macvlan driver: Macvlan networks are ideal for upgrading legacy applications via Cloud virtualization.
None driver: The none network driver does not connect containers to any network and as such, these containers can not communicate with other containers or machines.
Docker CLI Network Management
With the $ docker network --help
command, there are commands to append when searching for peculiar network information about the docker container network.
To list out all the networks running on docker with information about their network ID, name, network driver and scope
$ docker network ls
To find the IP, subnet, status, hash value, network ID and a host of information about the container in a comprehensive JSON format,
$ docker inspect <name of container or ID>
This is also the same way you want to inspect a network to get more information about it, the number and network details of containers running inside it.
- To create a new network on a local machine running the docker,
$ docker network creates <network driver’s name>
What this does is create a new default network driver for automatic network assignment on subsequent containers if there is no specific network assigned.
To add a custom network to network to a new container,
$ docker run -d --name <container name> --network <network driver name> <image>
To assign a custom network to a running container $
docker network connect <network name> <container name>
To disconnect a container from a network
$ docker network disconnect <network name> <container name or ID>
Article inspiration: Anshul od Udemy: DevOps Masterclass