caddy_docker_upstreams

package module
v0.0.0-...-ac5d7a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 17 Imported by: 0

README

Docker Dynamic Upstreams for Caddy.

This package implements a docker dynamic upstreams module for Caddy.

This is a fork which puts more emphasis on using the Caddyfile for routing instead of container labels.

Requires Caddy 2+.

Installation

Download from official website or build yourself using xcaddy.

Here is a Dockerfile example.

FROM caddy:<version>-builder AS builder

RUN xcaddy build \
    --with github.com/v4violet/caddy-docker-upstreams

FROM caddy:<version>

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Caddyfile Syntax

example.com {
  reverse_proxy /api/* {
    dynamic docker "api"
  }

  reverse_proxy {
    dynamic docker "frontend"
  }
}

Docker Labels

This module requires the Docker Labels to provide the necessary information.

Label Description
caddy required, should match the label in the Caddyfile (eg. caddy=api matches upstream definition of dynamic docker "api")
caddy.network optional but suggested if your container is attached to multiple networks, specify the docker network which caddy connecting through (if it is empty, the first network of container will be specified)
caddy.port optional unless the plugin cant auto detect the port

Example

# docker-compose.yaml
services:
  whoami:
    image: traefik/whoami:latest
    restart: always
    labels:
      - caddy=whoami
      - caddy.port=80
# Caddyfile
whoami.example.com {
  reverse_proxy {
    dyanmic docker "whoami"
  }
}

Docker Client

Environment variables could configure the docker client:

  • DOCKER_HOST to set the URL to the docker server.
  • DOCKER_API_VERSION to set the version of the API to use, leave empty for latest.
  • DOCKER_CERT_PATH to specify the directory from which to load the TLS certificates ("ca.pem", "cert.pem", "key.pem').
  • DOCKER_TLS_VERIFY to enable or disable TLS verification (off by default).

Documentation

Index

Constants

View Source
const (
	Label             = "caddy"
	LabelNetwork      = "caddy.network"
	LabelUpstreamPort = "caddy.port"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DockerUpstreams

type DockerUpstreams struct {
	Label string `json:"label,omitempty"`
	// contains filtered or unexported fields
}

func (DockerUpstreams) CaddyModule

func (DockerUpstreams) CaddyModule() caddy.ModuleInfo

func (*DockerUpstreams) GetUpstreams

func (du *DockerUpstreams) GetUpstreams(r *http.Request) ([]*reverseproxy.Upstream, error)

func (*DockerUpstreams) Provision

func (du *DockerUpstreams) Provision(ctx caddy.Context) error

func (*DockerUpstreams) UnmarshalCaddyfile

func (du *DockerUpstreams) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL