I am having issues reaching the internet from created LXC containers. In an Alpine container “apk add” gives an error, but after - echo "151.101.112.249 dl-cdn.alpinelinux.org" >> /etc/hosts – it works. Any suggestion of how to fix the DNS error.
Your containers do not get a DHCP lease, therefore they do not get their network autoconfigured.
Most likely there is a DNS server already running on the host and does not allow the DNS/DHCP server from within LXD to work. Any other DNS server on your host should NOT bind on the lxdbr0 interface.
To verify whether this is the case, please run on the host:
I ran lsof -i :domain which indicated the unbound resolver that I had installed on the host was indeed the issue. I uninstalled unbound on the host, and now everything is now working.
Would it be possible to install unbound within a LXC container on the host, then use that as a DNS resolver for the host. ?
I haven’t tried this. The potential problem is that the host will not have DNS until after the container has started and is ready to serve requests. In addition, you would need to configure the container to use a DNS server other than the one provided by DHCP from LXD. If you have a test computer, you can experiment.
unbound, however, by default should not bind to other interfaces other than loopback, unless you specify those other network interfaces. If I were you, I would make sure that unbound does not bind to lxdbr0.