-
-
Couldn't load subscription status.
- Fork 68
UsingMultipleDomainsIndexedLabels.md
DockFlare allows you to expose multiple hostnames from a single container, each with its own unique path, service target, or access policy. This powerful feature is enabled by indexed labels.
Instead of using simple labels like dockflare.hostname, you append an index number (starting from 0) before the key:
dockflare.0.hostnamedockflare.0.servicedockflare.1.hostnamedockflare.1.service- ...and so on for every setting.
Each index (0, 1, 2, ...) represents a distinct ingress rule. You still only need a single dockflare.enable="true" label to activate DockFlare for the container.
Important: Index numbers must be sequential starting from 0. If DockFlare finds labels for index 0 and 2 but not 1, it will stop processing after index 0.
This example uses a single container to expose a public website, a secure API on the same domain but a different path, and a status page on a completely different domain.
version: '3.8'
services:
# Your DockFlare service definition...
dockflare:
# ... (Configuration from Quick Start) ...
networks:
- cloudflare-net
# A single container exposing multiple rules
multi-app-gateway:
image: traefik/whoami # A simple service that echoes request info
container_name: multi-app-gateway
restart: unless-stopped
networks:
- cloudflare-net
labels:
# 1. Enable DockFlare for this container (only needed once)
- "dockflare.enable=true"
# --- Rule 0: The main public website ---
- "dockflare.0.hostname=www.example.com"
- "dockflare.0.service=http://multi-app-gateway:80"
# This rule is public by default as no access.policy is set.
# --- Rule 1: The secure API on a specific path ---
- "dockflare.1.hostname=www.example.com"
- "dockflare.1.path=/api"
- "dockflare.1.service=http://multi-app-gateway:80"
- "dockflare.1.access.policy=authenticate" # API requires login
# --- Rule 2: A status page on a different domain ---
- "dockflare.2.hostname=status.other-domain.org"
- "dockflare.2.service=http://multi-app-gateway:80"
- "dockflare.2.zonename=other-domain.org" # Specify the correct zone
- "dockflare.2.access.policy=bypass" # Explicitly public-
dockflare.enable="true": Activates DockFlare for themulti-app-gatewaycontainer. -
Index
0: Configureswww.example.comto be publicly accessible and handled by the backend service. -
Index
1: Configureswww.example.com/apito point to the same backend service, but this endpoint is protected by a Cloudflare Access policy that requires authentication. -
Index
2: Configuresstatus.other-domain.orgto be handled by the same container but specifies that its DNS record belongs in theother-domain.orgzone. It is made explicitly public with abypasspolicy.
This feature is powerful for:
- Exposing a web application and its secure API from the same container.
- Managing services across multiple domains you own.
- Applying different security policies or TLS settings to different paths on the same hostname.
DockFlare supports the use of wildcard hostnames (e.g., *.example.com) in your container labels. This allows you to route all traffic for any subdomain to a specific service, which is especially useful for multi-tenant applications or as a "catch-all" router.
You use the standard dockflare.hostname label but provide a wildcard hostname as the value.
This example configures a wildcard route for *.apps.example.com pointing to a single backend service.
version: '3.8'
services:
# Your DockFlare service definition...
dockflare:
# ... (Configuration from Quick Start) ...
networks:
- cloudflare-net
# This service will handle all requests to *.apps.example.com
wildcard-handler:
image: traefik/whoami # An example service that can show what hostname it received
container_name: wildcard-handler
restart: unless-stopped
networks:
- cloudflare-net
labels:
# --- DockFlare Labels ---
- "dockflare.enable=true"
# Define the wildcard hostname. This will match anything.apps.example.com.
- "dockflare.hostname=*.apps.example.com"
# Define the single target service for all matching subdomains
- "dockflare.service=http://wildcard-handler:80"-
dockflare.hostname="*.apps.example.com": This tells DockFlare to configure the Cloudflare Tunnel to route requests for any immediate subdomain ofapps.example.com(e.g.,test.apps.example.com,user1.apps.example.com, but notwww.test.apps.example.com) to the specified service. -
dockflare.service="http://wildcard-handler:80": All traffic matching the wildcard hostname will be forwarded to thewildcard-handlercontainer.
You can apply an Access Policy to a wildcard rule just like any other rule. For example, adding dockflare.access.policy="authenticate" would protect all subdomains.
Cloudflare Tunnels prioritize more specific rules over wildcards. This allows you to override the wildcard for specific subdomains. For example, if you have two containers:
-
Container A (Wildcard):
dockflare.hostname="*.example.com" -
Container B (Specific):
dockflare.hostname="specific.example.com"
- A request to
specific.example.comwill be routed to Container B. - A request to
another.example.comwill be caught by the wildcard and routed to Container A.
This makes wildcard routing a flexible and powerful tool for managing dynamic environments.