Bootstrap FreeKB - Docker - List networks using the docker network ls command
Docker - List networks using the docker network ls command

Updated:   |  Docker articles

The docker network ls command can be used to list networks.

docker network ls

 

Something like this should be returned.

NETWORK ID     NAME              DRIVER    SCOPE
7e6e54bde697   bridge            bridge    local
8ba129869d06   host              host      local
1143f39a14ae   none              null      local

 

bridge is the default network that is used when a container is created. Let's say you have used the docker pull command to pull down the tutum/hello-world image and then you start a container using the tutum/hello-world image. Let's break down this command.

  • The docker run command is used to start the container
  • The --detact flag is used to run the container in the background
  • The --publish 80 option is used to set the container to listen on port 80
  • The --name option is used to give the container the name "hello"
  • The tutum/hello-world image is used
sudo docker run --detach --publish 80 --name hello tutum/hello-world

 

Notice that we did not declare to use the bridge, host, or none network. Since bridge is the default network, the container is using the bridge network. Or, we could use the --network option to declare the network to use.

sudo docker run --detach --network bridge --publish 80 --name hello tutum/hello-world

 

The docker inspect command can be used to display the network being used by the container. Notice the container is using the bridge network.

  • Host IP address = 0.0.0.0
  • Host Port = 80:49155
  • Container IP address = 172.17.0.2
"NetworkSettings": {
    "Bridge": "",
    "SandboxID": "6a0832c2a37ad9659f4ee298a24900067465d7397ca17f87c517e59eb744fa56",
    "HairpinMode": false,
    "LinkLocalIPv6Address": "",
    "LinkLocalIPv6PrefixLen": 0,
    "Ports": {
        "80/tcp": [
            {
                "HostIp": "0.0.0.0",
                "HostPort": "49155"
            },
            {
                "HostIp": "::",
                "HostPort": "49155"
            }
        ]
    },
    "SandboxKey": "/var/run/docker/netns/6a0832c2a37a",
    "SecondaryIPAddresses": null,
    "SecondaryIPv6Addresses": null,
    "EndpointID": "e8b4d183b6afdcf123a19662a7e50ec1bb0ecfe46cf6234101870f96f97db24d",
    "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": "7e6e54bde697f7b2f1d8ce1102a396cfa5049974101fc1f3dc0395c0ef88839f",
            "EndpointID": "e8b4d183b6afdcf123a19662a7e50ec1bb0ecfe46cf6234101870f96f97db24d",
            "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
        }
    }
}

 

In fact, if we use the docker exec command to run the "ip address" command in the container, we can see that the container is using IP address 172.17.0.2.

~]# docker exec c0a71aa11337 ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
226: eth0@if227: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 860d5f in the box below so that we can be sure you are a human.