Docker networking enables communication between various containers and the external environment. It can be difficult to understand networking if you are new to Docker. This guide will provide examples and a straightforward explanation.
Containers communicate with other systems and with each other over Docker networking. Imagine it as your home's local network, where your computers, phones, and smart TVs are all connected to WiFi and can communicate to each other.
Docker offers a variety of networking options, each with a distinct function.
1. Bridge Network
Example: docker network ls # List all networks
docker run -d --name my_container nginx
docker inspect my_container | grep IPAddress # Check container's IP
Here, the container runs in a bridge network and gets an IP.
2. Host Network
The container shares the host machine’s network.
Useful when you don’t want network isolation between the container and the host.
Example:
docker run -d --name my_container --network host nginx
Here, nginx runs directly on the host network without its own IP.
3. None Network
The container has no network access.
Useful for security reasons when you don’t want external communication.
Example:
docker run -d --name my_container --network none nginx
4. Overlay Network
Example:
docker network create -d overlay my_overlay_network
5. Macvlan Network
Give a MAC address to the Docker container. With this Mac address, the Docker server routes the network traffic to a router.
Useful when containers need to be part of the external network.
Example:
docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 \
-o parent=eth0 \
my_macvlan_network
6.IPvLAN Network
Example:
docker network create -d ipvlan \
--subnet=192.168.70.0/24 \
--gateway=192.168.70.1 \
--aux-address="Ubuntu-Docker-Server=192.168.70.2" \
-o ipvlan_mode=l2 -o parent=eno1 ipvlan70
List all networks:
docker network ls
Inspect a network:
docker network inspect bridge
Remove a network:
docker network rm my_network
Docker networking helps containers communicate efficiently. Beginners should start with bridge and host networks before moving to advanced options like overlay and macvlan. By understanding how networks work, you can manage containerized applications better.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our DevOps Expertise.