lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
3.07k stars 174 forks source link

Add another example for a static configuration #596

Open Folas1337 opened 8 months ago

Folas1337 commented 8 months ago

While this might be obvious to people that know Caddy well, it wasn't for me and it took me a moment to figure out how to set this up.

There are use cases in which you can't rely on labels to configure your docker setup and you have to do it statically for whatever reason (as you have maybe connected your "ghetto swarm" through a VPN or you're only using swarm to have an overlay network but you're not really using the swarm functionality to deploy services as some services don't even scale with swarms). For those scenarios I would appreciate a static.yaml or something like that in the examples.

I migrated from the image SteveLTN/https-portal and needed a similar way of handling things by defining my proxy settings on the proxy container and not through labels on other containers šŸ˜„

Here's my current docker-compose.yml:

version: "3.7"
services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    container_name: caddy
    ports:
      - 80:80
      - 443:443
    environment:
      - CADDY_INGRESS_NETWORKS=caddy_network
    networks:
      - caddy_network
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - caddy_data:/data
    labels:
      caddy_1: container1.example.com
      caddy_1.reverse_proxy: "dockerContainer1:8080"
      caddy_2: container2.example.com, container.example.com
      caddy_2.reverse_proxy: "dockerContainer2:8081"
      #Add more containers to proxy here :)
    restart: unless-stopped

networks:
  caddy_network:
    driver: overlay

volumes:
  caddy_data: {}

Feel free to copy into the examples