Docker Networking 101

Table of contents
  • What is Docker Networking?

  • Types of Network drivers

  • some important docker networks command

  • Final Thoughts

what is Docker Networking?

  1. 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.

  2. A container has no information about what kind of network it’s attached to, or whether their peers are also Docker workloads or not.

  3. A container only sees a network interface with an IP address, a gateway, a routing table, DNS services, and other networking details.

  4. 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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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

  1. docker network ls - It is used to list all networks.bridge is the default network.

  2. docker network inspect bridge - it is used to inspect Bridge network to see what containers are connected to it.

  3. docker network inspect network_name - It is used to inspect network.

  4. docker network create --driver bridge network_name - It is used to create user-defined bridge network.

  5. 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.

  6. docker network connect container_name network_name -It is used to connect a running container to an existing user-defined bridge.

  7. docker network disconnect container_name network_name - It is used to disconnect a running container to an existing user-defined bridge.

  8. 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! πŸ”—βš™οΈ

10
Subscribe to my newsletter

Read articles from Nabin Kumar shaw directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nabin Kumar shaw
Nabin Kumar shaw