502 Bad Gateway when using secondary DNS record to point to docker container


I, like everybody else, am trying out Caddy and stumbled upon an issue which, hopefully, can be resolved here. Unfortunately every other topic is using Caddy v2 but my case is for v1.0.3.

Currently I have a Windows Server with a secondary DNS cname record “testing-stuff.url-resolver.domain.local”. We shall call it machine B.

For machine A I have a CentOS 7 which runs Docker 1.13.1 - due to sensitivity of the machine A I am trying to move certain production containers to the new machine B.

The second DNS record purpose is to avoid tedious reconfiguration should I decide to switch machine B to another host. That way DNS record gets reconfigured on another machine but Caddy configuration still points to the record.

Caddy v1.0.3 (abiosoft/caddy:1.0.3-no-stats) is currently running on Portainer v1.22.1 with pretty much everything default but ports being 80 on the host and 2015 on the container.

Caddyfile looks like this:

First two links point to Docker host (machine A) which houses certain containers and where portainer resides. The third link should do the same although it points from machine B to a docker container deployed on machine A.

The test is with Postman. If I enter “testing-stuff.url-resolver.domain.local:20421” with GET method everything works as intended. Although if I enter “testing-stuff.url-resolver.domain.local” I get 502 Bad Gateway. The idea is to map “testing-stuff.url-resolver.domain.local” to container without specifying port in the URL.

Would appreciate any ideas on how to solve given issue. Much appreciated.

Caddy v1 is no longer actively supported, I strongly recommend you upgrade to Caddy v2.

502 Bad Gateway means Caddy wasn’t able to connect to the upstream. There could be all kinds of reasons for this.

A common one is often the distinction between the host port and the internal docker port. Are you sure 20421 is the port of that service inside the docker network, rather than the binding to the host?

Ultimately this is more of a Docker usage question rather than a Caddy question.

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