Docker Networking Contd…
Docker has created a standard CNM (Container Networking Model). Core OS has developed one more standard CNI (Container Networking Interface).
Networking Articles:
Docker’s implementation of CNM is libnetwork.
Refer Here as this is what we are doing now
Experiments
Lets see the networks available in the docker host
Now lets create two alpine containers d1 and d2
bridge is the default network so lets inspect that
$ docker network inspect bridge
[
{
"Name": "bridge",
"Id": "e71220fbddbfb121ba7607584d225d4bd9830d52ed0f1dea3db54564a53d690e",
"Created": "2022-11-24T03:05:41.118857844Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"89359727c19cca0e02fe8ea9f658710286342a58783797fb8bba74590b7b6b2a": {
"Name": "d1",
"EndpointID": "20ddb68305cbf23f66b51d128fdf68223ba3813024568397eafb6a6cc0bf9365",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
},
"e0eb0287a9c35f9d101515c6ea88c2401479ff786b700e31f76d0f891c044cce": {
"Name": "d2",
"EndpointID": "f89b91e2cc6587ba621304bbc163d6fb1a9121dc3861c996c8c357ab58aec858",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
d1 has an ip 172.17.0.2 and d2 has an ip 172.17.0.3
Lets run ping from d1 to d2 using name and then ip
In default bridge network we are able to ping containers by its ip address
Now lets try to create our bridge network my_bridge
Now lets create two containers m1 and m2
Inspect the bridge network
[
{
"Name": "my_bridge",
"Id": "90b8b0d2ea383f8fa1f25507418b71296249327b5e23e4d86a0784973ea1a126",
"Created": "2022-11-24T03:20:11.297771156Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "10.10.10.0/24"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"53594ba2567529554bf7501b953f8fcd61a69a661df83d9290ba8528354be53f": {
"Name": "m1",
"EndpointID": "0fc70a57dec727ff231469fd61da4dbfb56d7bc29d2e13f4408f5277d7b5df62",
"MacAddress": "02:42:0a:0a:0a:02",
"IPv4Address": "10.10.10.2/24",
"IPv6Address": ""
},
"968db46fd2dc488ef2a758fe99b2717aa74c5b76a1eef643842a081511b5c25e": {
"Name": "m2",
"EndpointID": "bbde38feb3130f99f0e3566a51fba55bd3fad7428dbb63295ef4feeec45c29d8",
"MacAddress": "02:42:0a:0a:0a:03",
"IPv4Address": "10.10.10.3/24",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
Lets ping from m1 to m2 using name i.e. service discovery using DNS and then by ip
The network which we created is user defined bridge network
Containers can be disconnected from their original network and connected to new network. In the below example i’m connecting d1 from default brige to my_bridge
disconnect can be used to move the container back to its parent network.