Skip to content

Caddy Docker Reverse Proxy

Posted on:March 16, 2024

How to setup caddy as a reverse proxy with docker standalone and docker swarm.

Caddy service:

version: "3.9"
services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    ports:
      - 80:80
      - 443:443
    environment:
      - CADDY_INGRESS_NETWORKS=caddy
      - CADDY_DNS= ${token} cloudflare
    networks:
      - caddy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - caddy_data:/data
    restart: unless-stopped
    labels: # Global options
      caddy.email: [email protected]

networks:
  caddy:
    external: true

volumes:
  caddy_data: {}
# swarm
deploy:
  labels:
    caddy: <url>
    caddy.reverse_proxy: "{{upstreams <UPSTREAM_PORT>}}"

networks:
  caddy:
    external: true
# standalone

labels:
  caddy: <url>
  caddy.reverse_proxy: "{{upstreams <UPSTREAM_PORT>}}"

networks:
  caddy:
    external: true