Problem with .lxd domains on boot

I tried to move away from static IPs using container.lxd domains. But it seems that container.lxd domains are not available during server boot. Later I have no problem using it.

Two containers: https and tdb. First is nginx webserver, second is CMS. Nginx is reverse proxy:

proxy_pass              http://tdb.lxd/;
proxy_redirect          http://tdb.lxd;

This setup works ok if I start https container by hand. But if I reboot the server and log into https then I find nginx not started:

host not found in upstream "tdb.lxd" in /etc/nginx/conf.d/tdb.conf:15

But if run /etc/init.d/nginx start then nginx starts just fine. And ping tdb.lxd works too. And lxc restart https works too.

Any ideas how to deal with it?

There’s probably a race condition between your nginx process starting and the container starting and being allocated a dynamic IP by dnsmasq (which creates the DNS record).

It sounds like nginx only performs a DNS lookup for upstream hosts on startup, although perhaps there is a configuration option to change that.

Looks like there are some suggestions here