Cannot start caddy:2.0.0 under docker

1. Caddy version (caddy version):

2.0.0

2. How I run Caddy:

I am attempting to run caddy under docker using the first example given on the Docker hub page. I have created a simple index.html file and am trying to run the command listed to start but I receive the follow error before the container exits.

run: loading initial config: loading new config: starting caddy administration endpoint: listen tcp 192.168.1.65:2019: bind: cannot assign requested address

a. System environment:

Fedora 32, running docker with cgroups v2 disabled.
Docker version = 19.03.11

b. Command:

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

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

N/A: Using default Caddyfile

3. The problem I’m having:

When I try to run the Caddy container with the provided commands, the container exits after failing to bind the administration endpoint.

4. Error messages and/or full log output:

docker run --rm -p 80:80 -v $PWD/index.html:/usr/share/caddy/index.html -v caddy_data:/data caddy:2.0.0
{"level":"info","ts":1591213712.1576638,"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 192.168.1.65:2019: bind: cannot assign requested address

5. What I already tried:

I’ve tried running the command in a couple different ways, running as sudo, mapping the port to 8080:80 but it looks like the issue is happening inside the container which I don’t understand.

6. Links to relevant resources:

You must have something that’s making localhost resolve to 192.168.1.65 instead of the expected 127.0.0.1. You’ll need to investigate what’s causing that.

The workaround is simple though. At the top of your Caddyfile, put the following global option to override the default admin endpoint address:

{
	admin 127.0.0.1:2019
}

I ran dig against localhost and there is a record for the IP address that Caddy was trying to bind to. I changed my DNS server from my routers built in to Cloudflare’ 1.1.1.1 service and the error resolved.

1 Like

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