Using Docker Network

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

Instructions

$ docker network ls
$ docker network create -d bridge my-bridge-network
$ docker inspect app
"Networks": {
                "my-bridge-network": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "cf148e899ea8"
                    ],
                    "NetworkID": "82057fd5c45f1d62b0a96ac905af529ef6715e9f1038e6307f83b6698717dcfa",
                    "EndpointID": "24c5ac91c33c089427cf2f81cdc09c3ee4db09ecc0cb3b8298ba223689c10f4a",
                    "Gateway": "172.21.0.1",
                    "IPAddress": "172.21.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:15:00:02",
                    "DriverOpts": null
                }
            }
$ docker run -it --name client alpine:latest
$ apk --no-cache add curl  
$ curl 172.21.0.2:8081 --connect-timeout 5
$ curl: (28) Connection timed out after 5000 milliseconds
$ docker network connect my-bridge-network client
$ curl 172.21.0.2:8081 --connect-timeout 5
<h1>Python App</h1>
$ docker inspect my-bridge-network
"Containers": {
            "793a39c035a8988c1768f6061f1721ac124293502edb46ed16e06111f9bdbd61": {
                "Name": "client",
                "EndpointID": "1e2b7be275a10962c105fe01a85254ebb69dab33a60b1d9d9bc23bcfef1f337d",
                "MacAddress": "02:42:ac:15:00:03",
                "IPv4Address": "172.21.0.3/16",
                "IPv6Address": ""
            },
            "cf148e899ea8e91d9b12e2f1333bdbb144cebca9e088e6e5bfec63dd48c33ab8": {
                "Name": "app",
                "EndpointID": "24c5ac91c33c089427cf2f81cdc09c3ee4db09ecc0cb3b8298ba223689c10f4a",
                "MacAddress": "02:42:ac:15:00:02",
                "IPv4Address": "172.21.0.2/16",
                "IPv6Address": ""
            }
        },
$ docker network disconnect my-bridge-network app
$ docker network disconnect my-bridge-network client
$ docker network rm my-bridge-network
$ docker network ls
$ exit
$ exit

Next » Lab #1: Listing the Networks