Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "gateway" found in `docker inspect`?

I have the nginx running in docker(Docker for mac, using docker-compose), here is the "Networks" section of docker inspect.

{
    "Networks": {
        "laradock_backend": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": [
                "c189cabxfdf9",
                "nginx"
            ],
            "NetworkID": "f4f8d8ff07ae90d5758644968d96f2g653fc5188c895f19c2d08de92c46cc075",
            "EndpointID": "f8c6d5a8b061c75c44c2e078a65928a9b45dd91833fc05x7f249c64a180e84a1",
            "Gateway": "172.21.0.1",
            "IPAddress": "172.21.0.4",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:02:fc:15:10:05",
            "DriverOpts": null
        },
        "laradock_frontend": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": [
                "c189cab4ddg1",
                "nginx"
            ],
            "NetworkID": "7b410b1bd764617a3f6146862307f886681e57aaxf057e4308f1236e1558ffcb",
            "EndpointID": "0caa62bc5bbx600a5b1f260ebg11014e05394671ca347f818bfx819f43f7011e",
            "Gateway": "172.22.0.1",
            "IPAddress": "172.22.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "01:41:af:16:00:03",
            "DriverOpts": null
        }
    }
}

I'm not an expert on computer networking. But I use docker very frequently, I just want to understand a little better about what's happening whenever I connect to the docker container through my host machine (localhost).

Where I found each network has a "Gateway" there. I can't find such interfaces on my host machine. Where does the "Gateway" sits? Why we need such a thing?

Any simple charts would be helpful… Thanks.

like image 738
yaquawa Avatar asked Oct 17 '25 02:10

yaquawa


1 Answers

The gateway is the device that connects the network to the outside world. When a packet is sent to a destination that is not in the same network, the packet is sent to the gateway, which knows how to sent it to the next router and so on, until the packet receive at the destination.

In this case, this gateway device is virtual and its part of a bridge between the container and the host physical interface. This emulation is needed in order to permit the software that runs in the container to run as it would be on the host. It also separate the network of the container to the network of the host (the separation is the motive for which you use docker).

like image 95
Constantin Galbenu Avatar answered Oct 18 '25 14:10

Constantin Galbenu