Automatic backend off url?

1. The problem I’m having:

I want to be able to forward sub.subdomain requests backend things, but automatically

I use docker compose for everything and I want to be able to use container-name.d.example.com and automatically reverse proxy container-name to that address, without having to add an entry for every single one

I would likely restrict this entire sub.sub.domain with basic auth so that wont be much of a security problem, this is mainly so that I can have an outbound URL

2. Error messages and/or full log output:

N/A

3. Caddy version:

N/A

4. How I installed and ran Caddy:

Docker Compose

a. System environment:

Docker Compose
Arch Host (assume latest packages as of Nov 15, 2023 as that was latest update)

b. Command:

docker compose up -d

c. Service/unit/compose file:

caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    networks:
      - default
      - skynet
      - minecraft
    ports:
      - 80:80
      - 443:443
      - 2019/tcp ## exposes to local network
    volumes:
      - caddy_config:/config
      - ./caddy/caddy.conf:/etc/caddy/Caddyfile
      - ./caddy:/srv
      - ./.workspace:/workspace

  caddy-php:
    image: "php:7.2-fpm"
    container_name: caddy-php
    user: "1001:1001"
    restart: unless-stopped
    volumes:
      - ./caddy/:/srv
      - ./.workspace:/workspace
    networks:
      - default
    environment:
      UID: 1001
      GID: 1001

d. My complete Caddy config:

N/A for this question
Will provide if asked

You probably want GitHub - lucaslorentz/caddy-docker-proxy: Caddy as a reverse proxy for Docker

is there a way this can be easily integrated into my already existing webserver? Like would I be able to just add an entry for this in my current caddy files and let it handle the rest for that subdomain?

You just swap out your caddy:latest container with CDP’s and then you can add labels to each service to have Caddyfile config automatically generated from your running containers.

Will it work with containers that are not a part of the master compose file?
I have my “core services” file located in /docker, and then have secondary services such as minecraft servers in their own individual compose files

do I just add the lable and it automatically detects those?

EDIT:
Tried to just swap it out, added the label for my git server (in the root compose file) and it just doesnt work, it does not load my previous caddy files, nor does it actually proxy gitea, it just shows an blank page for domains that have “labels” for

Read its docs. You can specify a base Caddyfile, and you can configure the Docker network to use to detect containers.

Yeah I managed to get it to work, my dumb brain was using the wrong port in the “upstreams” config, need to get that caddyfile tho

1 Like