Docker networking enables containers to communicate with each other, the host, and external networks. Docker provides several network drivers: bridge, host, overlay, macvlan, and none. Understanding these is essential for secure and efficient container deployments. This guide configures Docker networking on Ubuntu 26.04 LTS.

Tested and valid on:

  • Ubuntu 26.04 LTS

Prerequisites

  • Ubuntu 26.04 LTS with Docker Engine installed
  • A user in the docker group

Step 1 – List Default Networks

docker network ls

Step 2 – Inspect a Network

docker network inspect bridge

Step 3 – Create a Custom Bridge Network

docker network create --driver bridge mynet
docker network ls | grep mynet

Step 4 – Connect Containers via Custom Network

docker run -d --name web --network mynet nginx:alpine
docker run -d --name api --network mynet node:22-alpine node -e 'require("http").createServer((r,s)=>s.end("api")).listen(3000)'
# Containers can reach each other by name:
docker exec web wget -qO- http://api:3000

Step 5 – Host Networking

Use host networking for maximum performance (no NAT overhead):

docker run --rm --network host nginx:alpine

Step 6 – Configure DNS

docker run --rm --dns 8.8.8.8 --dns 1.1.1.1 ubuntu nslookup google.com

Step 7 – Create a Macvlan Network

Macvlan assigns a MAC address to the container, making it appear as a physical device on your LAN:

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

Step 8 – Remove Networks

docker network disconnect mynet web
docker network rm mynet

Conclusion

Docker networking is configured on Ubuntu 26.04 LTS. Use custom bridge networks for container isolation, overlay networks for multi-host Swarm deployments, and macvlan for containers that need to appear as physical devices.