Using custom DNS servers inside a container

Hey all,

I’ve written a project to take data from a lightwaverf energy monitor and display it on a Grafana dashboard so I know how much electricity I’m using.

The full code is available on Github and it’s working really well as long as I don’t try and use the DNS entries from my local network.

My setup is fairly unique, however I need to point the container at a local DNS server so it can resolve the services inside the local network instead of relying on IP addresses and port numbers.

Is there an easy way to do this rather than having to edit the SD Card data before I boot, or without running a multi-container setup?

Thanks in advance,

Matt

P.S. This is what the dashboard looks like:

Hi,

Did you already try the solution described in the paragraph here https://www.balena.io/docs/learn/develop/runtime/#using-dns-resolvers-in-your-container to see if it solves your issue?

That’s not the issue here, I’m not running a resolver inside the container itself, I need the container to use a resolver on the local network so it can perform local lookups.

Hi,

According to this SO answer you can have dns property inside /etc/docker/daemon.json:

{"dns": ["your_dns_server_ip"]}

Copy daemon.json file to image like it’s done here:

COPY daemon.json /etc/docker/daemon.json

Please try this and let us know how it goes.