Docker Networking
Tags: devops, docker, beginners
Published: 2022-11-19 07:43:30

> Source from Zeal Vora,KPLABS Course(Premium Instructor at Udemy)
[Udemy](https://www.udemy.com/course/docker-certified-associate)

Zeal is one of my favorite author for docker. Please try to yourself 💖

**(Tip: HE is ready to give some discount for students 😜)**

Hi buddy, this is all are intermediate points. if you need to basic understanding please look at my previous docker beginner blog otherwise please ignore  
-----------------Table of content-----------------
------------------------------------------------------------------




1. Networking 

2. Type of networks in docker 

3. Publish the argument

4. Legacy approach 

5. Docker networking commands


-------------------------------------------------------------------------------

1. Networking 

Communication between the container or securely make the communication so we using the networking.


![docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt4bfxjqry3fp4i6nocz.jpg)

- Container security 
- Purpose of public and private containers

2. Type of networks in docker 

Based on microservice application need networking configuration was changed (private and public communication).

Docker0 interface is a default network card for docker.Inside of all network related activity based on docker0 virtual network card 

      

-     Bridge network
-     User define bridge network 
-     Host network
-     NAT network
-     None network
-     overlay
-     macvlan




Bridge network
-----------------------------------------------------------------------
A bridge network uses a software bridge that allows containers connected to the same bridge network to communicate while providing isolation from containers which are not connected to that bridge network


![dn](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pw6ixa68ne7j9j152a66.JPG)

* Bridge is default network for docker.Its easy to make the communication between inside and across the host.simply mention the diagram. its a two way communication 

If we do not specify a driver,  this is the type of network you are creating.

When you start Docker, a default bridge network (also called a bridge) is created automatically, and newly-started containers connect to it unless otherwise specified.

We also can create a User-Defined Bridge Network which is superior to the default bridge.
 



User define bridge network
-----------------------------------------------------------------------

- 
User-defined bridges provide automatic DNS resolution between containers.

- 
**Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy**. 

- 
On a user-defined bridge network, containers can resolve each other by name or alias.



Host network
------------------------------------------------------------------------

Connection establish the with-in the host its called host network.


![dn](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d6f2mpevo1bes71o2h5w.JPG)




NAT network(Network address translation)
-----------------------------------------------------------------------

It's kind of bridge network but one way transaction.some time database containers is a private network but update some necessary package via internet so in this case use this NAT.no one can ping the inside of container.

![nat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee5065nqp5lmkcz6al1s.JPG)



None network
--------------------------------------------------------------------------------------

If you want to completely disable the networking stack on a container, you can use the none network.

This mode will not configure any IP for the container and doesn’t have any access to the external network as well as for other containers.


------------------------------------------------------------------------




**3.Publish the argument**

We were discussing an approach to publishing container port to host.

`docker container run -dt --name webserver -p 80:80 nginx`

This is also referred to as a publish list as it publishes the only a list of the port specified.

There is also a second approach to publish all the exposed ports of the container.

`docker container run -dt --name webserver -P nginx
`
This is also referred to as a publish all.

In this approach, all exposed ports are published to random ports of the host.



---------------------------------------------------------------------------
**4.Legacy approach**

Before the Docker networks feature, you could use the Docker link feature to allow containers to discover each other and securely transfer information about one container to another container.

The --link flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link

-------------------------------------------------------------------------

**Docker networking commands**

See the available docker network interface 

`docker network ls`

See the available system network interface

`ifconfig`