codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐳

Docker

30 / 60 topics
10Docker Networking Basics11Volumes and Bind Mounts30Docker Networking Advanced46Docker Networking Advanced Topics
Tutorials/Docker/Docker Networking Advanced
🐳Docker

Docker Networking Advanced

Updated 2026-05-15
10 min read

Docker Networking Advanced

Introduction

In the previous sections, we covered the basics of Docker networking. Now, let's dive deeper into advanced networking concepts and configurations that can help you build more complex and robust applications.

Docker provides several networking modes, including bridge networks, host networks, overlay networks, and macvlan networks. Each mode serves different purposes and is suitable for various use cases. In this tutorial, we will explore these advanced networking features and how to configure them effectively.

Concepts

Bridge Networks

Bridge networks are the default network mode in Docker. They allow containers to communicate with each other and with the host machine. However, they operate within a private network by default, which can be limiting if you need external access or specific routing rules.

Customizing Bridge Networks

You can create custom bridge networks with specific configurations:

  • Subnet: Define a custom subnet for the network.
  • Gateway: Specify a gateway IP address.
  • IP Range: Limit the range of IP addresses that containers can use.
Terminal
{`$ docker network create --subnet=172.18.0.0/16 --gateway=172.18.0.1 my_bridge_network`}

Host Networks

Host networks allow a container to share the host's network stack. This means the container will use the same IP address as the host and can access all ports on the host.

Terminal
{`$ docker run --network=host nginx`}
Output
{`CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES
abc123def456   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 10 seconds             ecstatic_hopper`}

Overlay Networks

Overlay networks are used for communication between containers running on different Docker hosts. They enable multi-host networking and are essential for Docker Swarm.

Terminal
{`$ docker network create --driver=overlay my_overlay_network`}

Macvlan Networks

Macvlan networks allow containers to have their own MAC address and IP address directly on the host's network interface. This is useful when you need containers to appear as individual devices on the network.

Terminal
{`$ docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 my_macvlan_network`}

Examples

Custom Bridge Network Example

Let's create a custom bridge network and run two containers on it to demonstrate communication.

Terminal
{`$ docker network create --subnet=172.18.0.0/16 --gateway=172.18.0.1 my_bridge_network
$ docker run -d --name web1 --network=my_bridge_network nginx
$ docker run -d --name web2 --network=my_bridge_network nginx`}

To verify communication between the containers, you can use the ping command inside one of the containers:

Terminal
{`$ docker exec -it web1 ping web2`}
Output
{`PING web2 (172.18.0.3) 56(84) bytes of data.
64 bytes from web2 (172.18.0.3): icmp_seq=1 ttl=64 time=0.092 ms
64 bytes from web2 (172.18.0.3): icmp_seq=2 ttl=64 time=0.092 ms`}

Overlay Network Example

To demonstrate overlay networks, we need to set up a Docker Swarm cluster and create an overlay network.

Terminal
{`$ docker swarm init
$ docker network create --driver=overlay my_overlay_network
$ docker service create --name web_service --network=my_overlay_network --replicas=2 nginx`}

You can inspect the services and verify that they are running on different nodes:

Terminal
{`$ docker service ls
$ docker service ps web_service`}

Macvlan Network Example

To use a macvlan network, ensure you have a suitable parent interface (e.g., eth0) on your host.

Terminal
{`$ docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 my_macvlan_network
$ docker run -d --name web3 --network=my_macvlan_network nginx`}

You can verify that the container has its own IP address on the host's network:

Terminal
{`$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web3`}
Output
{`192.168.1.100`}

What's Next?

In the next section, we will explore Docker Swarm Advanced, which builds on these networking concepts to provide high-availability and scalable container orchestration.

Stay tuned for more advanced topics in Docker!


PreviousDocker Compose AdvancedNext Docker Swarm Advanced

Recommended Gear

Docker Compose AdvancedDocker Swarm Advanced