Trying to understand the docker networks, Docker creates the following networks automatically:
# docker network ls
NETWORK ID NAME D
Bridge network: Bridge is the default network in docker which is also called as docker0. It is the default network that bridges through the NAT firewall to the physical that your host is connected to. But, we don't care about it as all the containers will attach to this network and worked.
If you have any containers running, you could inspect the bridge network as,
$ docker network inspect bridge
....
"Containers": {
"145a2716d018c6fe8e9f93a81d88afd5a7437f0084ddb170c40761818e6d2f67": {
"Name": "nginx",
"EndpointID": "ea6cfa433f41e21e572f17473c8e5f5e5d82e9f19646e66fe23abda20a3836b8",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
...
Note: You can see that automatic IP address assigned to the container which is from the IPAM config subnet.
Host Network: is a special network which skips the virtual networking of docker and attach the container directly to host interface. It's really not recommended but, in certain situations, can improve the performance of high throughput networking and in other, you will loose out of few benefits of containerization.
$ docker container run -it --net=host nginx:alpine /bin/bash
None Network: is kind of equivalent to having an interface on your machine that's not attched to anything, but we can create our own. The none network adds a container to a container-specific network stack. That container lacks a network interface.
$ docker container run -it --network=none nginx:alpine /bin/bash
root@8cb783cd4509:/# ip -4 addr
1: lo: mtu 65536 qdisc noqueue qlen 1
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever