Search code examples
dockergraylog2

Address docker container by name when net="host"


I'm having some strange issues with docker's --net="host"

When deploying a container in a custom network, I can address it with it's name. But when specifying --net="host" instead of --net="customnetwork", no ports are exposed, and I cannot address the container in any way. Here's the host network inspection

docker network inspect host
[
    {
        "Name": "host",
        "Id": "663f54513dc2b631d6f81457a49374da3bc3193ac0617497c018c47520600e22",
        "Scope": "local",
        "Driver": "host",
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Containers": {
            "836433bfa612f84fa3d73dec0f920e47affc529b64636f5e1bf38a8b7ced2d75": {
                "Name": "elasticsearch",
                "EndpointID": "79950c18d12d6c7a6715135287d48c7963bed21c7b09b28f6d443b7040eea697",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            },
            "86d4bd0c232a350371131c300c417877e0fb0c54b831f85093b0d2228d9b4f1a": {
                "Name": "mongo",
                "EndpointID": "492022820dd1e0a634e63c97962575b0bffe1c137163cce4df30aa8da39d1159",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            },
            "e4b9179849afa529a6249b067c27953d0b187afdd5fac76112bb9b1369ae9556": {
                "Name": "graylog",
                "EndpointID": "e705eede1ddf897c8c4fc45ae6fcf77db8228b1a0c2d318f6045846e52951b93",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            }
        },
        "Options": {}
    }
]

As you can see, no IP addresses are assigned, and nothing changed anywhere.

I'm relatively new to docker, and maybe I missed something.

Some info regarding background:

I'm using docker to deploy graylog2. It references mongodb and elasticserach by their hostname, and needs to have the ability to listen to ports on the host to catch incoming log messages. The ports are configured post deployment.

Docker version: 1.10.3, build 20f81dd

Any help is appreciated.

Thanks for your time.


Solution

  • When you do a --net=host, there is no separate network, there's no port to forward since it's just listening on your host (you can't forward to yourself, especially since you have the port in use), and there's no separate IP, it's the IP of your host.