Available network drivers in Docker
Bridge networks
Create feenixdv-net network, driver type bridge.
[root@docker ~]# docker network create –driver bridge feenixdv-net
324611157eac5e68650976067639870decdcc9cd023200e268a11d6d5d85bc31
List all present driver.
[root@docker ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
45f7806105bf bridge bridge local
324611157eac feenixdv-net bridge local
0566f1cc5748 host host local
7f8891df9e47 mynet123 bridge local
abcbc188a54b none null local
Inspect the feenixdv-net network. This shows you its IP address and the fact that no containers are connected to it:
[root@docker ~]# docker network inspect feenixdv-net
[
{
"Name": "feenixdv-net",
"Id": "324611157eac5e68650976067639870decdcc9cd023200e268a11d6d5d85bc31",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1/16"
}
]
},
"Internal": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
Notice that this network’s gateway is 172.18.0.1, as opposed to the default bridge network, whose gateway is 172.17.0.1. The exact IP address may be different on your system.
Create your four containers.
[root@docker ~]# docker run -it –name feenixdv_net –network feenixdv-net -d -p 85:80 -v /var/www/html/:/usr/local/apache2/htdocs/ docker.io/httpd
93ba3ef62e21f73b1f64e6c1b2dd7c25c893718d89d3351bafe56879705ac46a
List container process.
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93ba3ef62e21 docker.io/httpd "httpd-foreground" 6 seconds ago Up 5 seconds 0.0.0.0:85->80/tcp feenixdv_net
Check bridge configuration.
[root@docker ~]# docker network inspect bridge feenixdv-net
.
.
"Internal": false,
"Containers": {
"93ba3ef62e21f73b1f64e6c1b2dd7c25c893718d89d3351bafe56879705ac46a": {
"Name": "feenixdv_net",
"EndpointID": "4e318b75284f71db3ccd6122ca3f446dfe97002265d49549b81f22207fd5ca1a",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
.
.
Here we can see container "feenixdv_net" IP assign to "IPv4Address": "172.18.0.2/16",
Cross check after connecting.
[root@docker ~]# docker exec -it 93ba3ef62e21 bash
root@93ba3ef62e21:/usr/local/apache2# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
8: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe12:2/64 scope link
valid_lft forever preferred_lft forever
Same configuration in the container.
On user-defined networks likefeenixdv-net, containers can not only communicate by IP address, but can also resolve a container name to an IP address. This capability is called automatic service discovery.
Host network
This series of tutorials deal with networking standalone containers which bind directly to the Docker host’s network, with no network isolation.
Start new container with host network.
[root@docker ~]# docker run -it –name feenixdv_Host_Net –network host -d -v /tmp/:/usr/local/apache2/htdocs/ docker.io/httpd
d0ce7cbc5c932c3659dbe42893b1430af6565e665424097ed4e076c188b6bb0e
[root@docker Packages]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d4a7b55745db docker.io/httpd "httpd-foreground" 2 minutes ago Up 2 minutes feenixdv_Host_Net
This container directly accessable from host ip.
For testing we can access page on browser and with "netstat" command.
[root@docker Packages]# docker stop d4a7b55745db
d4a7b55745db
[root@docker Packages]# netstat -tulpn | grep :80
[root@docker Packages]# docker start d4a7b55745db
d4a7b55745db
[root@docker Packages]# netstat -tulpn | grep :80
tcp6 0 0 :::80 :::* LISTEN 8223/httpd
Macvlan network
This series of tutorials deal with networking standalone containers which connect to macvlan networks. In this type of network, the Docker host accepts requests for multiple MAC addresses at its IP address, and routes those requests to the appropriate container. For other networking topics
Prerequisites
Most cloud providers block macvlan networking. You may need physical access to your networking equipment.
The macvlan networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.
You need at least version 3.9 of the Linux kernel, and version 4.0 or higher is recommended.
The examples assume your ethernet interface is eth0. If your device has a different name, use that instead.
Bridge example
In the simple bridge example, your traffic flows through eth0 and Docker routes traffic to your container using its MAC address. To network devices on your network, your container appears to be physically attached to the network.
[root@docker Packages]# docker network create -d macvlan –subnet=172.16.86.0/24 –gateway=172.16.86.1 -o parent=enp0s3 feenixdv-macvlan-net
aabd48f9e1b1c12c3825030a70dfffbc848342ac936befa44e54e1c91fe61046
[root@docker Packages]# docker network ls
NETWORK ID NAME DRIVER SCOPE
45f7806105bf bridge bridge local
aabd48f9e1b1 feenixdv-macvlan-net macvlan local
324611157eac feenixdv-net bridge local
0566f1cc5748 host host local
7f8891df9e47 mynet123 bridge local
abcbc188a54b none null local
Now start container with macvlan.
[root@docker Packages]# docker run -it -d -p 8881 –network feenixdv-macvlan-net –name feenixdv_macvlan docker.io/httpd
da3077767df5fd3414f091aefc09ef2a191572993e764c57c69da6b2ef3bed14
[root@docker Packages]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
da3077767df5 docker.io/httpd "httpd-foreground" 2 minutes ago Up 2 minutes feenixdv_macvlan
Inspect the my-macvlan-alpine container and notice the MacAddress key within the Networks key:
[root@docker Packages]# docker network inspect feenixdv-macvlan-net
[
{
"Name": "feenixdv-macvlan-net",
"Id": "aabd48f9e1b1c12c3825030a70dfffbc848342ac936befa44e54e1c91fe61046",
"Scope": "local",
"Driver": "macvlan",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.16.86.0/24",
"Gateway": "172.16.86.1"
}
]
},
"Internal": false,
"Containers": {
"da3077767df5fd3414f091aefc09ef2a191572993e764c57c69da6b2ef3bed14": {
"Name": "feenixdv_macvlan",
"EndpointID": "77162ef3f782a188dd20366dae78655571ba8ee3eb133ee1db5b73c6325e2493",
"MacAddress": "02:42:ac:10:56:02",
"IPv4Address": "172.16.86.2/24",
"IPv6Address": ""
}
},
"Options": {
"parent": "enp0s3"
},
"Labels": {}
}
]
overlay networks