Table of contents
What is Docker Networking?
Types of Network drivers
some important docker networks command
Final Thoughts
what is Docker Networking?
docker networking is a fundamental aspect of docker that enables communication between docker containers and external networks. It allows you to connect container together as well as connect container to the host machine and the other external resources.
A container has no information about what kind of network itβs attached to, or whether their peers are also Docker workloads or not.
A container only sees a network interface with an IP address, a gateway, a routing table, DNS services, and other networking details.
By default when you create or run a container using docker create a docker run the container doesn't expose any of its ports up to the outside world.
Types of Network drivers
bridge:- The default Bridge network is good for running containers that don't require special networking capabilities.user-defined Bridge network enable container on the same docker host to communicate with each other.A user-defined network typically defines an isolated network for multiple containers belonging to a common project or the component.
host:- host network share the host's network with the container when you use this driver,the container's network isn't isolated from the host.
overlay:- overlay networks are best when you need containers running on different docker hosts to communicate or when multiple applications work together using Swarm services.
macvlan:- Macvlan networks are best when you are migrating from a VM setup or you need a container to look physical Host on your network each with unique Mac addresses.
ipvlan:- IPvlan is similar to macvlan but doesn't assigned unique Mac addresses to a container considering using IPvlan when there's restrictions on the numbers of Mac addresses that can be assigned to a network interfaces or port.
none:- No Networking
Default Bridge Network
\> Containers can communicate to each other
\> Containers and Host can communicate via bridge
\> Containers can only communicate by IP address, not by container name
User-defined Bridge Network
\> possible to achieve isolation of container.
\> C1 and C2 can communicate to C1 and C2 but can communicate Host via bridge net1.
\> Containers can communicate by Ip address & also resolve a container name to an Ip address.
some important docker networks command
docker network ls - It is used to list all networks.bridge is the default network.
docker network inspect bridge - it is used to inspect Bridge network to see what containers are connected to it.
docker network inspect network_name - It is used to inspect network.
docker network create --driver bridge network_name - It is used to create user-defined bridge network.
docker run --name container_name -itd --network network_name image_name - It is used to connect a container to a specified network. e.g host,user-defined bridge.
docker network connect container_name network_name -It is used to connect a running container to an existing user-defined bridge.
docker network disconnect container_name network_name - It is used to disconnect a running container to an existing user-defined bridge.
docker network rm network_name - It is used to delete specified network.
Final Thoughts
Thank you for exploring this guide on Docker networking! π I hope it made the topic clearer and easier for you to use in your projects. ππ‘
If you have any questions or thoughts to share, feel free to comment below. π¬π Iβd love to hear how Docker is helping you in your work! πβ¨
Happy coding! π³ Keep learning, keep building, and keep getting better with Docker! πβοΈ