lucaslorentz / caddy-docker-proxy

Caddy as a reverse proxy for Docker
MIT License
2.61k stars 163 forks source link

Upstreams macro not inserting container IP into caddy config #567

Closed jeffbrl closed 6 months ago

jeffbrl commented 6 months ago

I am executing a docker compose YAML configuration in portainer. My objective is to front a python app with caddy-docker-proxy. My interpretation of the docs is that I can use caddy.reverse_proxy: "{{upstreams http 5000}}" to insert an entry in caddy's config to proxy http traffic to port 5000 of the current container with that associated label. The resulting caddy configuration is not what I expect. I acknowledge that I may be misinterpreting the documentation.

YAML

version: '3.7'
services:
    fbm:
        image: python:3.11.7-slim-bullseye
        container_name: fbm
        volumes:
            - fbm:/app
        restart: unless-stopped
        command: "tail -f /dev/null"
        networks:
          fbm:
    fbmweb:
        image: python:3.11.7-slim-bullseye
        container_name: fbmweb
        volumes:
            - fbmweb:/app
        command: ["python", "-m", "http.server", "5000"]
        restart: unless-stopped
        labels:
          caddy: http://
          caddy.reverse_proxy: "{{upstreams http 5000}}"
        networks:
          fbm:
    caddy:
      image: lucaslorentz/caddy-docker-proxy:2.4.0
      ports:
        - 8480:80
        - 8483:443
      networks:
        fbm:
      restart: unless-stopped
      volumes:
        - fbm-caddy-data:/data
        - fbm-caddy-config:/config/caddy
        - /var/run/docker.sock:/var/run/docker.sock

volumes:
    fbm:
      external: true
    fbmweb:
      external: true
    fbm-caddy-data:
      external: true
    fbm-caddy-config:
      external: true

networks:
  fbm:

Here is the resulting caddy config.

root@docker10:/var/lib/docker/volumes/fbm-caddy-config/_data# cat autosave.json
{"admin":{"listen":"tcp/localhost:2019"},"apps":{"http":{"servers":{"srv0":{"listen":[":80"],"routes":[{"handle":[{"handler":"reverse_proxy"}]}]}}}}}root@docker10:/var/lib/docker/volumes/fbm-caddy-config/_data# cat autosave.json  | jq .
{
  "admin": {
    "listen": "tcp/localhost:2019"
  },
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":80"
          ],
          "routes": [
            {
              "handle": [
                {
                  "handler": "reverse_proxy"
                }
              ]
            }
          ]
        }
      }
    }
  }
}
root@docker10:/var/lib/docker/volumes/fbm-caddy-config/_data#

I expected to see the IP address of the 'fbmweb' container and port 5000. What mistake or incorrect assumption have I made?

francislavoie commented 6 months ago

lucaslorentz/caddy-docker-proxy:2.4.0 is a super old version. Please use the latest.

jeffbrl commented 6 months ago

Oops. That label is cited in the README. I assumed it was recent. I will try again with the latest commit.

jeffbrl commented 6 months ago

v2.8.10 behavior functions as expected. Thanks for the software. Great stuff.