Fela Maslen
Fela Maslen

Reputation: 2172

DNS lookup from dokku container

I'm running a node app inside a dokku container on an Ubuntu server, which also runs bind9 for DNS. In the node app, I'm running express. On the node app, I'm running a DNS reverse lookup on the client's IP like this (simplified):

const dns = require('dns');
const app = require('express')();

app.get('/myhostname', (req, res) => {
  dns.reverse(req.headers['x-forwarded-for'], (err, hostnames) => {
    res.json({ hostname: hostnames[0] });
  });
});

This works fine locally, but once deployed to the dokku container, fails with an ENOTFOUND error. Presumably this is because the app isn't set to use the Ubuntu server as its DNS server. So I tried this right after require('dns'):

dns.setServers([process.env.DNS_SERVERS])

where DNS_SERVERS is set to either the local LAN ip of the server, or its docker internal IP. Either of those addresses results in a delay and eventual timeout trying to get the address.

How should I go about this?

Upvotes: 0

Views: 420

Answers (1)

Fela Maslen
Fela Maslen

Reputation: 2172

The solution was this:

  • Set DNS_SERVERS=172.17.0.1

  • Allow requests through the firewall on the docker0 interface

  • Make sure bind is listening on 172.17.0.1 and that it is set to allow requests from the 172.17.0.0/16 range

The second item on the list is what I wasn't considering...

Upvotes: 2

Related Questions