Docker has Three built in network drivers on linux hosts
- Host Driver (Single Network 'host')
- Null Driver (Single Network 'None')
- Bridge Driver (Single default network 'bridge' )
- No Virtual Container network, bind container directory to host Network.
- Container shared IP Address of host system.
- Docker doesn't allow creating additional host network.
- No Virtual Container network, no binding to host network.
- Full isolation.
- Docker doesn't allow creating additional none network.
```bash
$ docker run -d --net none --name c1 nginx:alpine
$ docker inspect c1
### Locate IP Address
$ docker inspect c1 -f "{{.NetworkSettings.IPAddress}}"
## Expected is NO IP Address
## Delete the container
$ docker stop c1
$ docker rm c1
```
- Virtual Network "Subnet" with dedicated IP Address range.
- Isolate / Group containers into multiple bridge networks
- Allow Local network / Internet access from inside container.
- Allows User-defined bridge networks created with non-overlapping IP address ranges.
-
Create two bridge networks with IP Address ranges.
$ docker network create b1 -d bridge --subnet 20.0.0.0/16 $ docker network create b2 -d bridge --subnet 30.0.0.0/16 $ docker network ls
-
Create containers in network
b1
andb2
$ docker run -d --name c1 --net b1 nginx:alpine $ docker run -d --name c2 --net b2 nginx:alpine $ docker run -d --name c3 --net b2 nginx:alpine
-
Get IP Addresses for ALL containers
$ docker inspect c1 -f "{{.NetworkSettings.Networks.b1.IPAddress}}" # You should get 20.0.0.2 $ docker inspect c2 -f "{{.NetworkSettings.Networks.b2.IPAddress}}" # You should get 30.0.0.2 $ docker inspect c3 -f "{{.NetworkSettings.Networks.b2.IPAddress}}" # You should get 30.0.0.3
-
Try to ping container c3 from container c1 [Impossible]
$ docker exec -it c1 sh $ ping 30.0.0.3 $ exit
-
Try to ping container c2 from container c3 [Possible]
$ docker exec -it c3 sh $ ping 30.0.0.2 $ exit
-
Clean-Up
$ docker stop c1 c2 c3 $ docker rm c1 c2 c3 $ docker network rm b1 b2