Caddy on Docker trying to bind to random DNS address, not starting

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

a. System environment:

macOS Catalina host, running inside Docker.

b. Command:

docker run -p 80:80 \     
    -v $PWD/index.html:/usr/share/caddy/index.html \
    -v caddy_data:/data \
    caddy

3. The problem I’m having:

Simply running the above command results in an error. This command is pulled from the official caddy docker image.

I believe that this issue is because of a misconfigured host, but I’m not sure how to solve it. The issue doesn’t seem to be affecting any other applications besides this one.

4. Error messages and/or full log output:

{“level”:“info”,“ts”:1590298497.854198,“msg”:“using provided configuration”,“config_file”:“/etc/caddy/Caddyfile”,“config_adapter”:“caddyfile”}
run: loading initial config: loading new config: starting caddy administration endpoint: listen tcp 45.90.28.0:2019: bind: cannot assign requested address

5. What I already tried:

Since I believe there is an issue with the host computer, I’ve spent most of my time trying to figure out what to do about host configuration. Firstly, the hosts file:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

It was modified, and I tried to make it as vanilla as possible to make sure that that is not the issue. Also, I restarted to make sure that localhost is configured correctly.

When I run:

% host localhost
localhost.ade5bb.dns.nextdns.io has address 45.90.28.0
localhost.ade5bb.dns.nextdns.io has IPv6 address 2a07:a8c0::

I also get the same IP address that Caddy was trying to bind to. I’m not totally sure about this since I’m not sure whether the host command ignores /etc/hosts or not. But it seems to be a clue since the address it resolves to is the same as the one caddy is trying to bind to. This address is NextDNS’s IPv4 address.

I tried changing the DNS servers to see if that would change localhost. I changed them to Cloudflare’s DNS in my settings, resulting in a resolv.conf that looks like this:

search ade5bb.dns.nextdns.io
nameserver 1.1.1.1
nameserver 1.0.0.1

Even then, the result of host localhost is the same and Caddy is still trying to bind to that address. I’m not totally sure what to do next.

That’s so weird.

I don’t have the slightest clue why that would be happening.

As a workaround, if you run Caddy from a config (Caddyfile or JSON) then you can change the admin address used. In a Caddyfile, it would look like this:

{
	admin 127.0.0.1:2019
}

I mean that worked. It is really a weird issue though. Let me know if you need any more information about it.

Here’s the thing…

The search there is the clue. Basically what search does is prepending whatever bare host you’re checking to the domain set as search domain. So when you try to dig localhost, MacOS sees it isn’t FQDN, so it converts it to one by morphing it to localhost.<search domain>, i.e. localhost.ade5bb.dns.nextdns.io, which NextDNS catches through some wildcard and resolves it to their own IP address.

Source: macos - What is the "Search Domains" field for in the tcp/ip DNS settings control panel/preference pane for? - Super User

Interesting. Do you think it can be safely removed? I have that set in my router config, which is why it’s the default on my computer. But if it’s not necessary, I can just remove it.

@francislavoie Do you know the name of that config? Is it documented somewhere?

I appreciate your help!

That depends on your network environment and your network/router admin. If you set it yourself in your router config, were you following a guide that asked you to add it? I’d be surprised if any of your apps, if any, that bind to localhost work at all with such config.

Of what config? I’m not sure I understand the question. admin is a global option (as I linked to) if that’s what you mean.

@Mohammed90 Yes, it was just the NextDNS setup guide. All other apps that bind to localhost for local development do work thought, so that is strange.

@francislavoie Yes, that’s what I meant, I didn’t see your link the first time. Thank you for the help!

This topic was automatically closed after 30 days. New replies are no longer allowed.