Welcome back! After covering basic networking, Docker Compose, Swarm, and logging, itβs time to tackle advanced Docker networking for multi-host setups. This is essential when deploying scalable applications across multiple machines.
πΉ Why Advanced Networking?
- Containers need to communicate across different hosts.
- Overlay networks allow seamless communication between containers on different machines.
- Useful for Swarm clusters or distributed applications.
πΉ Overlay Network
- Overlay networks connect multiple Docker daemons (hosts) together.
- Automatically encrypts traffic between nodes in a Swarm.
Creating an Overlay Network
docker network create -d overlay my_overlay
-
-d overlay
specifies the overlay driver.
Connecting Services
docker service create --name web --replicas 3 --network my_overlay nginx
- Services can now communicate across nodes transparently.
πΉ Multi-Host Networking Example
- Initialize Swarm on the first host:
docker swarm init --advertise-addr <MANAGER-IP>
- Join worker nodes:
docker swarm join --token <WORKER-TOKEN> <MANAGER-IP>:2377
- Deploy a service on the overlay network.
- Check communication between replicas across nodes:
docker service ps web
docker exec -it <container_id> ping <other_container_name>
πΉ Macvlan Networks
- Allows containers to appear as physical devices on the network.
- Useful for legacy apps or apps that need direct LAN access.
Example:
docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 \
-o parent=eth0 my_macvlan
πΉ Best Practices
- Use overlay networks for multi-host apps.
- Use bridge networks for isolated services on a single host.
- Avoid exposing all ports publicly.
- Use VLAN or Macvlan only when necessary for network integration.
πΉ Hands-On Challenge
- Create an overlay network.
- Deploy a 3-replica Nginx service across Swarm nodes.
- Test inter-container communication.
- Experiment with Macvlan for a container needing LAN access.
β Next Episode: Episode 23 β Docker Swarm Advanced: Services, Secrets & Configs β mastering orchestration features for production-ready deployments.
Top comments (0)