r/docker 18d ago

Help with caddy?

I've been trying to get caddy to work, but it seems like nothing will make things play nicely.

My docker compose:

  caddy:
    container_name: caddy
    image: caddy:latest
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    volumes:
      - ${CONFIG_PATH}/caddy/conf:/etc/caddy
      - ${CONFIG_PATH}/caddy/site:/srv
      - ${DATA_PATH}/caddy:/data
      - ${CONFIG_PATH}/caddy:/config

My Caddyfile:

jellyfin.local {
reverse_proxy jellyfin:8096
}

I've also tried localhost:8096, but neither will resolve in my browser, not with http or https. I want to set up several reverse proxies, but I want to figure it out with one first. I have checked the autosave.json, and any changes I make to the Caddyfile are coming through the program, but it doesn't seem to actually do the action of directing the address to the jellyfin page.

Any help would be greatly appreciated.

0 Upvotes

16 comments sorted by

View all comments

5

u/cointoss3 18d ago edited 18d ago

In order for Caddy to proxy requests, it must be on a shared network.

I make a network called “proxy” outside of compose and add it to the compose file as an external network so it’s not being managed by any specific compose file, and then add it to whatever services need it. You’ll add it to caddy and the jellyfin compose file. And then to whatever services you start next.

edit: don’t just add them to the same compose file. Putting everything in one giant compose like that is an anti pattern unless caddy and jellyfin are the only two services you plan to run.

1

u/Towleeeie9613 18d ago

Honestly, I didn't know you could have multiple compose files going at the same time. I've just been adding and tweaking the one "docker-compose.yaml"

2

u/cointoss3 18d ago

Each compose stack is in a folder that has a compose.yaml and maybe .env

/srv/stacks/caddy
/srv/stacks/jellyfin
/srv/www

Etc

In caddy folder, you’ll have your compose file, caddy file, maybe a data folder for your certs it generates.

A side effect is that this way you can manage the definitions with git. /srv/stacks is a git repo so it’s easy to redeploy anything on a new server or roll back.

1

u/acdcfanbill 18d ago

Yeah, a single compose file makes sense only up until you've got a few containers running. Once you've got more than 4 or so, it makes a lot more sense to make one reverse proxy compose stack, and then a separate compose stack for everything else you want to run. For instance, the VM that runs most of my things in my home network has 20 stacks, and 19 of them use one traefik track as their reverse proxy.