Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating reverse proxy only works via Caddyfile, not labels #586

Open
ericgroom opened this issue Mar 1, 2024 · 2 comments
Open

Creating reverse proxy only works via Caddyfile, not labels #586

ericgroom opened this issue Mar 1, 2024 · 2 comments

Comments

@ericgroom
Copy link

Probably a dumb configuration issue, but I think I have a minimal example and have double checked instructions. This reverse proxy works when configured via a Caddyfile, but not via the labels.

compose.yml

services:
  whoami0:
    image: traefik/whoami
    networks:
      - caddy
    labels:
      caddy: test.mydomain.dev
      caddy.reverse_proxy: "{{upstreams 80}}"
  caddy:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      - CADDY_INGRESS_NETWORKS=caddy
      - CADDY_DOCKER_CADDYFILE_PATH=/etc/caddy/Caddyfile
      - GOOGLE_DOMAINS_ACCESS_TOKEN=${GOOGLE_DOMAINS_ACCESS_TOKEN}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - caddy_data:/data
      - ./Caddyfile:/etc/caddy/Caddyfile
    networks:
      - caddy

volumes:
  caddy_data: {}

networks:
  caddy:
    external: true
    name: caddy

Dockerfile

FROM caddy:2.7.6-builder AS builder

RUN xcaddy build \
    --with github.com/caddy-dns/google-domains \
    --with github.com/lucaslorentz/caddy-docker-proxy/v2

FROM caddy:2.7.6

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Caddyfile

{
    email redacted@redacted.com
    acme_dns google_domains {env.GOOGLE_DOMAINS_ACCESS_TOKEN}
}

test.mydomain.dev {
    reverse_proxy whoami0 # caddy and docker are on the same network, so using hostname works fine
}

I've tried without a Caddyfile and get the same result; I'd like to keep it as I have some redirects I'd like to do outside of proxying to containers. I never see any log messages in the caddy container when spinning up containers using caddy labels so I assume it's not seeing them start up?

Any help debugging would be much appreciated!

@francislavoie
Copy link
Collaborator

What does "doesn't work" mean? What error do you see? What's in your logs? Show an example request with curl -v. Enable the debug global option.

@funkyapple
Copy link

This may not be related, but I had the same issue where the caddy-docker-proxy module was not loading. This resulted in labels not working. I fixed this by changing to the alpine version of the caddy docker image.

FROM caddy:builder AS builder

RUN xcaddy build \
    --with github.com/lucaslorentz/caddy-docker-proxy/v2

FROM caddy:alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

CMD ["caddy", "docker-proxy"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants