caddy-docker-proxy
caddy-docker-proxy copied to clipboard
Is it possible to inject directives in an existing service?
sorry -- this is a question and not an Issue but the ""Discussions" tab is not enabled"
I want to change an existing service's definitions in caddy, from another service's docker-compose. Specifically, if you take the example of wildcards in the caddy documentation
*.example.com {
tls {
dns <provider_name> [<params...>]
}
# Fallback for otherwise unhandled domains
handle {
abort
}
}
This would go directly into caddy's docker-compose labels and then each new site, from its own docker-compose YAML, would need to "inject" into the configuration above blocks such as
@foo host foo.example.com
handle @foo {
respond "Foo!"
}
Is this possible?
Yes, labels with the same site address get merged.
Yes, labels with the same site address get merged.
OK thank. I understand that you mean that when adding extra *.example.com entries in specific docker-compose files, it will be merged. If so I will try to go for configurations such as
caddy: *.example.com
caddy.@foo: host foo.example.com
caddy.handle.@foo: respond "Foo!"
and see how it goes
Yes, labels with the same site address get merged.
Sorry if I'm hijacking this issue, but wouldn't this mean that something like this should work? @francislavoie
services:
example1:
networks:
- caddy
labels:
caddy: example.com
caddy.reverse_proxy: "{{upstreams 80}}"
example2:
networks:
- caddy
labels:
caddy: example.com
caddy.reverse_proxy: "/api {{upstreams 8080}}"
networks:
caddy:
external: true
This should proxy all traffic to example.com/api to the example2 container, did I understand that correctly? Also, would this work if example1 would be in a different compose file than example2?
Path matching is exact. /api only matches that, and not /api/foo. Use /api/* instead.