How do I refer to the 'LXD host from an LXD container

We currently run our services in a series of LXD containers - we have one running a nginx server as a reverse proxy, pointing at each service, and where I need to connect to a container from the host or another container, I use the LXD assigned hostname. It works very well, and its extremely clean.

I'm currently looking at setting up grafana for monitoring in a container and hook in a prometheus instance in the host to feed it data. It would probably be helpful to be able to refer to the LXD host by a hostname - like I do for the containers for this and other projects. What would be the 'correct' way to refer to the host from a service running on a container?


Solution 1:

If you are using a LXD managed network, which sets up a bridged network and also runs a dnsmasq DHCP server to provide the behaviour you describe, the host is reachable under the domain name _gateway.<domain>, e.g. _gateway.lxd (or just _gateway using DNS search suffixes). Requires minimum LXD 4.16.

If you are using any other network type, including unmanaged bridges, then there is no built-in way to do so.

Note that to actually access a service on the host using the _gateway name, the service must be listening on the LXD bridge interface/address.