Caddy with Home Assistant in Docker

Hi all,

I am attempting to get Caddy working as a reverse proxy to connect to HA via domain internally with SSL.

I’ve got the following docker compose for Caddy:

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
    ports:
      # - "192.168.100.2:80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ${DATA}/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ${DATA}/caddy/data:/data
      - ${DATA}/caddy/config:/config
      - ${DATA}/caddy/logs:/var/log/caddy
      - /etc/ssl:/etc/caddy/certs
    networks:
      caddy_network:
         ipv4_address: 172.100.0.10 # Assign a static IP within the subnet

networks:
  caddy_network:
    name: caddy_network
    driver: bridge # This is the default, but explicitly stating it is good practice
    ipam:
      config:
        - subnet: 172.100.0.0/24 # Define the subnet for your network
          gateway: 172.100.0.1 # Optional: Define a gateway for the subnet

The following Caddyfile

# Global options
{
    debug # For Caddy's internal process logs
    log {
        output file /var/log/caddy/caddy.log {
            roll_size 10MB
            roll_keep 5
            roll_keep_for 720h # 30 days
        }
        level INFO # Or DEBUG for more verbose process logs
    }
}

sarah.mycustomdomain.com {
    tls /etc/caddy/certs/certs/*.mycustomdomain.com.fullchain.pem /etc/caddy/certs/keys/*.mycustomdomain.com.pem

    reverse_proxy 192.168.100.2:8123

    log {
        output file /var/log/caddy/access.log {
            roll_size 10MB
            roll_keep 5
            roll_keep_for 720h
        }
        format json # Recommended for structured access logs
        # level INFO # Access logs are typically INFO level by default
    }
}

However I do not seem to be getting anywhere.

Caddy is starting, doing a dns lookup I get the IP responding as 172.20.0.10 as per the dockerfile but nothing in the browser.

If I sh into Caddy, and do a curl I can confirm it can reach the HA container.
Yet there is nothing in the access log :frowning:

Anyone any ideas how to get this working? Would really appreciate assistance in getting this going.

Thanks!

What does an extrernal curl on https://sarah.mycustomdomain.com produce?

I get:

curl: (28) Failed to connect to sarah.mycustomdomain.com port 443 after 21050 ms: Could not connect to server

Ok I managed to solve the issue.

Issue was the router/firewall had no idea where to route the traffic, so I needed to put a DNAT entry into the firewall so it could translate the IP to the docker host.

Once I got that running, everything began working.