Caddy and DockStarter 502 error

1. Caddy version (caddy version):

v2.4.5

2. How I run Caddy:

a. System environment:

ubuntu, docker

b. Command:

docker-compose up

c. Service/unit/compose file:

version: "3.7"

services:
  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
    external: true
  caddy_config:

d. My complete Caddyfile or JSON config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

media.ryanrambharose.dev {
        # Set this path to your site's directory.
        #root * /usr/share/caddy

        # Enable the static file server.
        #file_server

        # Another common task is to set up a reverse proxy:
        reverse_proxy jellyfin:8096

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}
bitwarden.ryanrambharose.dev {
        reverse_proxy bitwarden:8013
}
portainer.ryanrambharose.dev {
        reverse_proxy portainer:9001
}
chat.ryanrambharose.dev {
        reverse_proxy synapse:8008
}
chat.ryanrambharose.dev:8448 {
        reverse_proxy synapse:8008
}
irc.ryanrambharose.dev {
        reverse_proxy thelounge:9000
}
pihole.ryanrambharose.dev {
        reverse_proxy pihole:8009
}

3. The problem I’m having:

Run Caddy with Dockstarter and Docker

4. Error messages and/or full log output:

caddy_1 | {“level”:“error”,“ts”:1636127149.278481,“logger”:“http.log.error”,“msg”:“dial tcp: lookup portainer on 127.0.0.11:53: no such host”,“request”:{“remote_addr”:“174.92.13.211:51687”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“portainer.ryanrambharose.dev”,“uri”:"/",“headers”:{“User-Agent”:[“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36”],“Sec-Fetch-Site”:[“none”],“Sec-Fetch-Mode”:[“navigate”],“Sec-Fetch-User”:["?1"],“Cache-Control”:[“max-age=0”],“Sec-Ch-Ua”:["“Chromium”;v=“95”, “;Not A Brand”;v=“99"”],“Sec-Ch-Ua-Mobile”:["?0"],“Sec-Ch-Ua-Platform”:["“Windows”"],“Upgrade-Insecure-Requests”:[“1”],“Accept”:[“text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”],“Sec-Fetch-Dest”:[“document”],“Accept-Encoding”:[“gzip, deflate, br”],“Accept-Language”:[“en-US,en;q=0.9”]},“tls”:{“resumed”:false,“version”:772,“cipher_suite”:4865,“proto”:“h2”,“proto_mutual”:true,“server_name”:“portainer.ryanrambharose.dev”}},“duration”:0.002577361,“status”:502,“err_id”:“26f9egj6t”,“err_trace”:“reverseproxy.statusError (reverseproxy.go:858)”}

5. What I already tried:

Instead of localhost I set it to the docker container name and port. I think the issue might be due to networks being different?

6. Links to relevant resources:

Which version exactly? Please run caddy version in the container to find out. Often, users think they’re using the “latest” but they aren’t. The latest version if v2.4.5.

Yep, that’s the most likely problem. Docker’s built-in DNS server wasn’t able to resolve the container name to an IP address, and that’s because the caddy container and your other services don’t share a Docker network in common.

Either put all your services in a single docker-compose.yml which will implicitly cause them to all share a network, or create an external network which you configure each service to use.

How would I do the latter?

I believe I want to add to compose_default

NETWORK ID     NAME              DRIVER    SCOPE
1316fb9393b1   bridge            bridge    local
acfdcb356ed6   caddy_default     bridge    local
9900fa56f777   compose_default   bridge    local
09a0d102f741   host              host      local
5145f6b18ce7   none              null      local

If you mean to get the version, then you can run:

docker-compose exec caddy caddy version

For docker networking, please read the Docker documentation:

1 Like

Ok now my compose file look like this. Same error. Should I using port 8096 on jellyfin?

version: "3.7"

services:
  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
    external: true
  caddy_config:
networks:
  default:
    external: true
    name: compose_default

Ok thanks for you help it works now

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