Mastering Docker Networking: Docker Networking Best Practices

            Docker networking refers to the networking capabilities and features provided by Docker to enable communication between containe...

   


 
    Docker networking refers to the networking capabilities and features provided by Docker to enable communication between containers, between containers and the host system, and even between containers across different hosts in a networked environment. Docker uses a flexible networking model that allows containers to be connected to different types of networks, each serving a specific purpose.

Docker Network Types:

  1. bridge

  2. host

  3. overlay

  4. IPvLAN

  5. Macvlan

  6. None

Default Bridge Network:

When Docker is installed, a default bridge network named bridge is created. Containers attached to this network can communicate with each other by default, but they are isolated from the host machine and from containers on other bridge networks

User-Defined Bridge Networks:

Users can create their own bridge networks using the docker network create command. Containers connected to user-defined bridge networks can communicate with each other and with containers on the default bridge network.

Host Network:
Containers can be run with the --network host option, which makes them share the network namespace with the host. This means they share the same network interfaces and can directly bind to host ports.

Overlay Network:
Docker supports multi-host networking using overlay networks. Containers on different hosts can communicate with each other using overlay networks. This is especially useful in distributed or swarm-mode environments.

IPvLAN:

IPvLAN is an advanced driver that offers precise control over the IPv4 and IPv6 addresses assigned to your containers, as well as layer 2 and 3 VLAN tagging and routing.

This driver is useful when you’re integrating containerized services with an existing physical network. IPvLAN networks are assigned their own interfaces, which offers performance benefits over bridge-based networking.


Macvlan Network:
Docker supports the creation of Macvlan networks, allowing containers to be directly connected to a physical network. This enables containers to have their own MAC address and appear as physical devices on the network.

None:

IP addresses won’t be assigned to containers. These containments are not accessible to us from the outside or from any other container.


To List the networks in docker we need to use below command
Command: docker network ls
To check the Network details run the docker image as a container and use docker inspect to check the network of the particular docker container. Command: docker inspect container-id Example: docker inspect 0feb7bf95284


To Create the Custom Network
Command: docker network create --driver <driver-name> <bridge-name>

Example: docker network create --driver bridge test-network Inspect the Newly created network Command: docker network inspect bridge-name or network id Example: docker network inspect 8d345e4c704d (or) test-network

If you want to create the network with your custom Range with a customer gateway you can use other options 

To check the options use the below command
Command: docker network create –help
command: docker network create -d bridge --subnet network range with cidr  --gateway gateway-ip Network-name
Example: docker network create -d bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 techiev



If we want to use our custom docker network for our container we can pass the --network option in the docker run command
Command: docker run -d --network=network_name dockerimage_name
Example: docker run -d --network=techiev httpd



Now we need to inspect and check the network ip of the httpd container.


Now we have the IP address within the given network range 192.168.0.0/16

To remove all the unused Docker Networks
Command: docker network prune

The disconnect command can be used to remove a Container from the Network.
Command: sudo docker network disconnect <network-name> <container-name>
Example: docker network disconnect techiev e33944a83920

If you want to delete the docker network.
Command: docker network rm Network name (or) id
Example: docker network rm techiev
Now we can able to create the custom network and reuse it with the existing containers also, but if want to use those networks in your dockerfile or docker-compose file you can use them.
----------------------------------------!!!! Happy Learning with Techiev !!!!!!!!----------------------------------

-------------------------Subscribe our Youtube Channel by clicking the below link---------------------- ----------------------------!!https://www.youtube.com/@techieview729!!---------------------




Name

AWS,14,Devops,23,linux,9,
ltr
item
Techie View: Mastering Docker Networking: Docker Networking Best Practices
Mastering Docker Networking: Docker Networking Best Practices
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE_f9Rgd8Pr_8szDeupJU3p_S3hqzPdLyTMhmeLb-mZejnmIckkPpLNbNCajrvwp3KB1LIOEc2V9-8eguhdCuWTbpo0sc8SiWNaEQiWcC7A0N-fEHWTg_mfpaO8XjeG-nuRcMlhKHOBbPYV4SmAkN4qaZew-4S-Y-M0dGOUCct-6YSnk4PSnjhsQNcnBCZ/w640-h334/Docker-Networking-Concepts.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE_f9Rgd8Pr_8szDeupJU3p_S3hqzPdLyTMhmeLb-mZejnmIckkPpLNbNCajrvwp3KB1LIOEc2V9-8eguhdCuWTbpo0sc8SiWNaEQiWcC7A0N-fEHWTg_mfpaO8XjeG-nuRcMlhKHOBbPYV4SmAkN4qaZew-4S-Y-M0dGOUCct-6YSnk4PSnjhsQNcnBCZ/s72-w640-c-h334/Docker-Networking-Concepts.png
Techie View
https://www.techiev.com/2024/01/mastering-docker-networking-docker.html
https://www.techiev.com/
https://www.techiev.com/
https://www.techiev.com/2024/01/mastering-docker-networking-docker.html
true
7013663511659419322
UTF-8
Loaded All Posts Not found any posts VIEW ALL View Full Article Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy