Cloud

Docker Networking: Bridge, Host, Overlay — Sysadmin Guide 2026

Docker Networking: Bridge, Host, Overlay — Sysadmin Guide 2026

Docker microservices in production, and suddenly, two containers can’t communicate. Same host, same machine. The problem: two separate bridge networks, internal DNS not configured. It took 30 minutes to find, and two lines of code to fix. This all-too-common scenario highlights how critical understanding Docker networking fundamentals is for anyone managing modern IT infrastructure. Incorrect network configuration can transform a robust architecture into a troubleshooting nightmare, impacting SLAs and response times. With the increasing adoption of containers, the ability to design, implement, and debug efficient Docker networks has become an essential skill for every sysadmin and DevOps engineer. The Cloud Native Computing Foundation (2025) reports that 70% of service outages in containerized environments are linked to network or resource configuration issues. This guide provides the foundational knowledge and practical configurations to master key Docker network drivers, ensuring your containers communicate securely and efficiently.

Prerequisites / Test Environment

To follow this guide, you will need a Linux environment with Docker installed and running. Recent Docker Engine versions (24.x or higher) are recommended. For the overlay network sections, a minimum two-node Docker Swarm cluster will be necessary.

Docker Network Drivers: bridge, host, overlay, macvlan, none

Docker offers several network drivers, each designed for specific use cases and architectural requirements. Understanding the differences between these drivers is crucial for selecting the most suitable solution for your environment. Each driver defines how containers connect to each other and to the outside world.

  • Bridge: The default driver. It creates a private internal network for containers on a single host.
  • Host: Removes network isolation between the container and the host, allowing the container to directly use the host’s network stack.
  • Overlay: Enables communication between containers residing on different Docker hosts, essential for Swarm clusters.
  • Macvlan: Assigns a MAC address and IP from the physical network directly to the container, making it appear as a physical device on the network.
  • None: Completely disables networking for the container, useful for containers that do not require network connectivity.

To view the available networks on your Docker system, use the command:

docker network ls

This will show you the default networks (bridge, host, none) and any custom networks you have created.

Bridge Network: The Default and Its Limitations

When you start a container without specifying a network, Docker automatically connects it to the default bridge network. This network creates a virtual bridge (docker0 on Linux) that allows containers on the same host to communicate with each other using their internal IP addresses. However, this network has significant limitations:

  1. Limited Isolation: All containers on the default bridge network can reach each other. There is no logical isolation between different applications.
  2. DNS Resolution: Containers can communicate via IP, but DNS resolution by name between containers is not automatic on the default bridge network.
  3. Static Configuration: You cannot configure specific parameters like subnets or gateways.

For simple applications or quick tests, the default bridge network might suffice. But for production environments with microservices, it is advisable to switch to user-defined bridge networks.

User-Defined Bridge: Isolation and Automatic DNS

User-defined bridge networks offer superior network isolation and automatic DNS resolution capabilities between connected containers. Each custom network creates a separate virtual bridge, ensuring that only containers explicitly attached to that network can communicate with each other. This improves the security and manageability of your architecture.

To create a custom bridge network:

docker network create --driver bridge --subnet 172.20.0.0/16 mynet

This command creates a network named mynet with the specified subnet. Now you can start containers and attach them to this network:

docker run -d --net mynet --name webserver nginx
docker run -d --net mynet --name appserver myapp:latest

The webserver and appserver containers can now communicate with each other using their names as hostnames, thanks to the internal DNS provided by Docker. To inspect the network and see connected containers:

docker network inspect mynet

You can also assign a specific IP to a container, although this is less common and often discouraged unless specific needs arise, as Docker manages DHCP within the network:

docker run -d --net mynet --ip 172.20.0.10 --name fixedip_nginx nginx

Host Network: When and Why to Use It

The host driver removes network isolation between the container and the host. The container shares the host’s network stack, meaning it does not have its own separate IP address. Ports exposed by the container will be directly mapped to the same ports on the host. This can improve performance by removing the NAT layer but also introduces security risks and port collisions.

Use cases:

  • High-performance applications: If every millisecond counts and virtual network stack latency is an issue.
  • Monitoring: Monitoring tools that need to access all host network interfaces.
  • Specific network services: Containers that need to interact directly with network hardware or low-level protocols.

To start a container in host network mode:

docker run -d --net host --name myhostapp myapp:latest

It is crucial to be aware of the risks: the container has access to all host network interfaces, including services listening on localhost. This driver should be used with caution and only when strictly necessary.

Overlay Network: Multi-Host Communication with Swarm

Overlay networks are the backbone of communication between containers distributed across multiple Docker hosts. They are essential for microservices architectures that require horizontal scalability and orchestration, such as those managed by Docker Swarm. A Swarm cluster uses an internal key-value store (based on Raft) to maintain the state of the network and services.

To create an overlay network (requires an initialized Swarm cluster):

  1. Initialize Swarm (if not already done):
docker swarm init --advertise-addr <MANAGER_IP>
  1. Create the overlay network:
docker network create --driver overlay --attachable myoverlay

The --attachable flag allows standalone containers (not part of a Swarm service) to connect to this network.

  1. Start a Swarm service on the network:
docker service create --replicas 3 --network myoverlay --name myweb nginx

The myweb service containers, even if distributed across different hosts in the Swarm cluster, will be able to communicate with each other and with other containers on the myoverlay network using their service names or container names (if created with --attachable).

Macvlan: Containers with IPs on the Physical Network

The macvlan driver allows you to assign a unique MAC address to a container, making it appear as a physical device on the network. This means the container obtains an IP address directly from the physical network, as if it were a virtual machine or a hardware device. It is particularly useful in scenarios requiring:

  • Integration with legacy networks: Applications that need to be on the same subnet as existing physical devices or VMs.
  • IP Isolation: When a container needs to have a public IP or an IP on a specific VLAN.
  • IoT/Specialized Networking: Containers that need to interact with low-level network devices or specific protocols.

To create a macvlan network:

docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 mymacvlan

Replace eth0 with your host’s physical network interface. Now you can start a container that obtains an IP from your physical network:

docker run -d --net mymacvlan --name mymacvlan_nginx nginx

Caution: macvlan configuration can be complex and requires good knowledge of your physical network. Ensure your switch supports promiscuous mode or that you have configured VLANs correctly, if applicable.

Docker Compose Networking: Practical Examples

Docker Compose simplifies the management of multi-container applications by defining their configuration (including networking) in a docker-compose.yml file. By default, Compose creates a user-defined bridge network for all services defined in the file, allowing them to communicate by name.

Example docker-compose.yml:

version: '3.8'
services:
  web:
    image: nginx
    ports:
      - "80:80"
    networks:
      - app_net

  app:
    image: myapp:latest
    networks:
      - app_net

networks:
  app_net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.21.0.0/24

In this example, web and app are on the same app_net and can communicate with each other. If you omit the networks section at the service level, Compose will connect them to the default network automatically created for the project.

Read also: Proxmox VE: Complete Installation & Configuration Guide 2026

Debugging Docker Networks: Tools and Commands

Debugging Docker network issues is a fundamental skill. Here are some useful commands:

  • Inspect a network: docker network inspect provides complete details about the network, including connected containers, subnet, gateway, and DNS settings.
  • List networks: docker network ls shows all existing Docker networks.
  • Test connectivity between containers: Use docker exec to enter a container and use tools like ping or curl to test connectivity to other containers or external services.
docker exec webserver ping appserver
  • Check logs: Container logs can often reveal connection errors or timeouts.
  • Firewall: Ensure that host firewalls (like ufw or firewalld) are not blocking traffic between containers or to exposed ports.

A common error is forgetting that containers on different bridge networks cannot communicate without explicit routing or the use of overlay networks. When a service is unresponsive, the first step is to check the container’s and host’s network configuration.

Common Errors and Troubleshooting

  1. Containers not communicating: Often caused by containers being on different bridge networks. Verify with docker network inspect and ensure relevant services are on the same user-defined bridge network, or consider an overlay network for multi-host environments.
  2. Ports inaccessible from outside: This could be a port mapping issue (-p host_port:container_port) or a host firewall blocking traffic. Ensure the host port is open and not in conflict.
  3. DNS resolution failure: If containers cannot resolve each other by name, verify they are on the same user-defined bridge network or that your external DNS service is correctly configured if you are using a different driver. docker network inspect will show the DNS servers configured for the network.
  4. IP address conflict: If you create networks with subnets that overlap with your physical network or other Docker networks, you might experience routing problems. Choose unused subnets.

According to a 2024 survey, 40% of Docker production incidents are attributable to incorrect or insufficient network configurations (Container Security Report, 2024).

FAQ — Frequently Asked Questions

What is the docker0 network?

docker0 is the virtual bridge interface created by Docker upon installation, serving as the connection point for the default bridge network. All containers that do not specify a network connect to docker0 and obtain an IP from its range. Docker automatically manages it and you should not modify it manually.

When should I use a user-defined bridge network instead of the default one?

You should use a user-defined bridge network for most of your production applications. It offers better isolation between containers, automatic DNS resolution by container name, and greater flexibility in subnet configuration. This creates a more secure and manageable environment for your microservices.

What is the difference between host network and bridge network?

The bridge network creates network isolation between the container and the host, assigning the container an internal IP and using NAT for external communication. The host network, on the other hand, removes this isolation, allowing the container to directly use the host’s network interface and stack. The host network offers higher performance but is less secure.

Can I connect a container to multiple networks?

Yes, a container can be connected to multiple networks simultaneously. This can be useful for complex scenarios where a container needs to communicate with services on different networks, for example, a container exposing an API on a public network and communicating with a database on a private, isolated network. You can achieve this by specifying multiple --net flags or by configuring multiple networks in Docker Compose.

Conclusions with Operational Takeaways

Understanding and correctly configuring Docker networking are fundamental pillars for the stability and security of your containerized applications. From the simplicity of the default bridge network to the strategic complexity of overlay for Swarm clusters, each driver plays a specific role. Adopting user-defined bridge networks for isolation and internal DNS resolution is an indispensable best practice for production environments. Always remember to inspect your networks (docker network inspect) and test connectivity to prevent and quickly resolve issues. Investing time in mastering these configurations will save you hours of debugging and ensure the resilience of your systems.

Updated: June 2026

Read also: Linux Hardening: 15-Point Checklist for Production (2026)

Read also: Ansible Playbook Provisioning Server: Checklist 12 Task Automatizzati (2026)

Read also: Zabbix 7 Installation: Ubuntu 24.04 Setup Guide

Share this article:

Written by

Rosario Giordano

Rosario Giordano is a system administrator and IT consultant specializing in cybersecurity and cloud, with over 20 years of experience managing enterprise Linux infrastructures. His areas of expertise include SSH hardening, Kubernetes platforms, PostgreSQL databases, VMware/ Proxmox virtualization, and compliance with NIS2 and ISO 27001 security frameworks