Docker Networking Tutorial

Docker Networking Tutorial

Docker makes it fairly easy to set up virtual networking in a local environment. In fact, in using Docker to this point, we haven’t had the need to tinker with any network settings as typically the network portion of Docker “Just Works”. In other words, the defaults provided are common to work with but you can change any of the default options with regard to networks under the hood. Most of the networking in Docker revolves around the ports in use and how to expose those ports for various services in containers. Most times, the bridge default virtual network is used but we’ll see how to create, connect to, and disconnect from additional networks as needed.


Docker Network Defaults

Some of the defaults when working with Docker Networks are as follows.

  • Each container is connected to a private virtual network named bridge.
  • Each virtual network routes through the NAT on the host IP.
  • All containers on the same virtual network can talk to each other with no need for exposing ports (-p)
  • The defaults work well in most cases but can be customized if needed.
  • You can create networks as needed, or use the host IP (–net=host)
  • You can attach containers to any number of networks, or none if you don’t need any.

Docker Network Ports

The first thing we’ll look at when networking with Docker is the -p option. This option flag is short for –publish, which creates a firewall rule which maps a port on the container to a port on the host machine to the outside world. In the following example, an Nginx container is started with the name of webhost. The flag in bold -p 80:80, specifes to map TCP port 80 in the container to port 80 on the host. Publishing ports is in the format of HOST:CONTAINER.

> docker container run -p 80:80 --name webhost -d nginx
c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd

The docker container port command shows us in a nice format which ports are forwarding traffic from the host to the container.

> docker container port webhost
80/tcp -> 0.0.0.0:80

Docker IP Addressing

To find the IP Address of a container, we can use the docker container inspect command. In the example here we are using the –format option to format the results of our command in a user friendly way. Our webhost container has the IP address of 172.17.0.2 as we can see.

> docker container inspect --format '{{ .NetworkSettings.IPAddress }}' webhost
172.17.0.2

Listing Docker Networks

The docker network ls command shows all of the networks that have been created. The bridge network is the default docker virtual network which is behind NAT’d behind the host IP Address. The host network skips virtual networks altogether for performance reasons, but is less secure. The none network can be thought of like a network port that is unplugged.

> docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
313d57da9944        bridge              bridge              local
4c835cce5ea0        host                host                local
085638da5c3d        none                null                local

Inspecting Docker Networks

We can use the docker network inspect command to find out what containers are connected to what network. The output below shows us that the webhost container which has an IP address of 172.17.0.2 and a subnet mask of 16 bits, is connected to the bridge network. Docker networks automatically assign IP addresses, and the configuration of that is handled in the IPAM section.

> docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "313d57da9944030d011fc7f86938007a67aa2c201f3642db3ad4b86f1560cf2e",
        "Created": "2020-10-05T12:54:39.6042375Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
        },
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "Containers": {
            "c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd": {
                "Name": "webhost",
                "EndpointID": "2e6f46886aae647928688b3ca8b3cf9894a2cf40e99cf0bc92dec05a2e3399a7",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/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": {}
    }
]

Create A Docker Network

To create a virtual network in Docker, use the docker network create command and pass it the name you would like the network to have. This creates a new virtual network that you can attach containers to.

> docker network create my_network
66e9d0a4537bf8a8b6771720f5226ce809ca8ac7ecb1e5ba66a36df6068c7194

Now when we list out the networks again, there is a new entry with the name of my_network and the driver of bridge. The bridge driver is the default driver that creates a virtual network for you with sensible defaults beginning at 172.17.

> docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
313d57da9944        bridge              bridge              local
4c835cce5ea0        host                host                local
66e9d0a4537b        my_network          bridge              local
085638da5c3d        none                null                local

If you needed to customize the settings for your virtual network, the –help menu gives you an overview of what can be configured.

> docker network create --help

Usage:  docker network create [OPTIONS] NETWORK

Create a network

Options:
      --attachable           Enable manual container attachment
      --aux-address map      Auxiliary IPv4 or IPv6 addresses used by
                             Network driver (default map[])
      --config-from string   The network from which copying the configuration
      --config-only          Create a configuration only network
  -d, --driver string        Driver to manage the Network (default "bridge")
      --gateway strings      IPv4 or IPv6 Gateway for the master subnet
      --ingress              Create swarm routing-mesh network
      --internal             Restrict external access to the network
      --ip-range strings     Allocate container ip from a sub-range
      --ipam-driver string   IP Address Management Driver (default "default")
      --ipam-opt map         Set IPAM driver specific options (default map[])
      --ipv6                 Enable IPv6 networking
      --label list           Set metadata on a network
  -o, --opt map              Set driver specific options (default map[])
      --scope string         Control the network's scope
      --subnet strings       Subnet in CIDR format that represents a
                             network segment

Connecting Containers To Networks

When you spin up a container, you can specify the network it will connect to if you like. Below we are spinning up a second webhost named webhost2, and we are assigning it to the new network that we just created named my_network.

> docker container run -d --name webhost2 --network my_network nginx
40c5fe69890498159920ec5a775eb3583289253372bfdf5c63f4e32a3db5ab31

When inspecting the my_network network, we see that container connected to the network successfully.

> docker network inspect my_network
[
    {
        "Name": "my_network",
        "Id": "66e9d0a4537bf8a8b6771720f5226ce809ca8ac7ecb1e5ba66a36df6068c7194",
        "Created": "2020-10-05T15:10:43.1263348Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "40c5fe69890498159920ec5a775eb3583289253372bfdf5c63f4e32a3db5ab31": {
                "Name": "webhost2",
                "EndpointID": "265a958fff7085094f4497c7cc34d933685708f5ea434700f28e981dcd475257",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Now, let’s also connect the original container we had running to this new network. This can be done with the docker network connect command.

> docker network connect my_network webhost

Now when we inspect that container, it shows that it is connected to 2 networks. It is connected to bridge, as well as my_network.

> docker container inspect webhost
[
    {
        "Id": "c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd",
        "Created": "2020-10-05T14:54:15.1858603Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 816,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-10-05T14:54:16.1634567Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:7e4d58f0e5f3b60077e9a5d96b4be1b974b5a484f54f9393000a99f3b6816e3d",
        "ResolvConfPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/hostname",
        "HostsPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/hosts",
        "LogPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd-json.log",
        "Name": "/webhost",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                30,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97-init/diff:/var/lib/docker/overlay2/b873da3ee35fed4ed5b663d42705f29857e467ef7fc70d4f01b34e8593c90a2d/diff:/var/lib/docker/overlay2/c37b3ca864167a02502bc473d368823bdf2fdddf7ef3ff0fda126aae98ccf5c3/diff:/var/lib/docker/overlay2/d0b819fd09a7a62a2fc9858b4a015cd5594a240caefce77cad9a6b0f596f0dca/diff:/var/lib/docker/overlay2/5d3260b5420b271959560369b58594ca2be7fd8ae7bd74822c24c765c8ebeafc/diff:/var/lib/docker/overlay2/d874cfda684973a0d7f77e451987cd726723eab53aabf2ef285000ff32101e3d/diff",
                "MergedDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/merged",
                "UpperDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/diff",
                "WorkDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "c4198f018c0b",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.19.2",
                "NJS_VERSION=0.4.3",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "753e34a80acb2c9bcbb47344ef1a9ad7815d59e8151bfc61d84f1ee5d8f390d6",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/753e34a80acb",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "2e6f46886aae647928688b3ca8b3cf9894a2cf40e99cf0bc92dec05a2e3399a7",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "313d57da9944030d011fc7f86938007a67aa2c201f3642db3ad4b86f1560cf2e",
                    "EndpointID": "2e6f46886aae647928688b3ca8b3cf9894a2cf40e99cf0bc92dec05a2e3399a7",
                    "Gateway": "172.17.0.1",
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                },
                "my_network": {
                    "IPAMConfig": {},
                    "Links": null,
                    "Aliases": [
                        "c4198f018c0b"
                    ],
                    "NetworkID": "66e9d0a4537bf8a8b6771720f5226ce809ca8ac7ecb1e5ba66a36df6068c7194",
                    "EndpointID": "117ac3c34ccf85838684684b61b93848455c4be8b6685833f15b81b88d09813d",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:03",
                    "DriverOpts": {}
                }
            }
        }
    }
]

Remove Container From A Network

To remove a container from a network, use the docker container disconnect command. The example here disconnects the webhost container from the my_network network.

> docker network disconnect my_network webhost

An inspection confirms that this container is no longer connected to both networks. It only has the connection to the original bridge network now.

> docker container inspect webhost
[
    {
        "Id": "c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd",
        "Created": "2020-10-05T14:54:15.1858603Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 816,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-10-05T14:54:16.1634567Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:7e4d58f0e5f3b60077e9a5d96b4be1b974b5a484f54f9393000a99f3b6816e3d",
        "ResolvConfPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/hostname",
        "HostsPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/hosts",
        "LogPath": "/var/lib/docker/containers/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd/c4198f018c0b90df3b5958bb892f015bc5afdeb8efba863a1439e8ad6c32ccfd-json.log",
        "Name": "/webhost",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                30,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97-init/diff:/var/lib/docker/overlay2/b873da3ee35fed4ed5b663d42705f29857e467ef7fc70d4f01b34e8593c90a2d/diff:/var/lib/docker/overlay2/c37b3ca864167a02502bc473d368823bdf2fdddf7ef3ff0fda126aae98ccf5c3/diff:/var/lib/docker/overlay2/d0b819fd09a7a62a2fc9858b4a015cd5594a240caefce77cad9a6b0f596f0dca/diff:/var/lib/docker/overlay2/5d3260b5420b271959560369b58594ca2be7fd8ae7bd74822c24c765c8ebeafc/diff:/var/lib/docker/overlay2/d874cfda684973a0d7f77e451987cd726723eab53aabf2ef285000ff32101e3d/diff",
                "MergedDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/merged",
                "UpperDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/diff",
                "WorkDir": "/var/lib/docker/overlay2/c443ff100dfbc9cb2f5b0618b35d4f8f6db3bbc06afb1889a3ba7f80f778ee97/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "c4198f018c0b",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.19.2",
                "NJS_VERSION=0.4.3",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "753e34a80acb2c9bcbb47344ef1a9ad7815d59e8151bfc61d84f1ee5d8f390d6",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/753e34a80acb",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "2e6f46886aae647928688b3ca8b3cf9894a2cf40e99cf0bc92dec05a2e3399a7",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "313d57da9944030d011fc7f86938007a67aa2c201f3642db3ad4b86f1560cf2e",
                    "EndpointID": "2e6f46886aae647928688b3ca8b3cf9894a2cf40e99cf0bc92dec05a2e3399a7",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

Learn More


Docker Networking Tutorial Summary

Listed below are some of the commands we had a look at in this docker networking tutorial. We can see how to create, list, inspect, connect to, and disconnect from virtual networks in a Docker environment.

  • docker network ls – Lists all the networks the Engine daemon knows about. This includes the networks that span across multiple hosts in a cluster.
  • docker network inspect – Returns information about one or more networks. By default, this command renders all results in a JSON object.
  • docker network create – Creates a new network. The DRIVER accepts bridge or overlay which are the built-in network drivers. If you have installed a third party or your own custom network driver you can specify that DRIVER here also. If you don’t specify the –driver option, the command automatically creates a bridge network for you.
  • docker network connect – Connects a container to a network. You can connect a container by name or by ID. Once connected, the container can communicate with other containers in the same network.
  • docker network disconnect – Disconnects a container from a network. The container must be running to disconnect it from the network.