Sign inSign up

mishamx/caddy

By mishamx

•Updated almost 8 years ago

Caddy with plugins from source using Docker multi-build

Image
0

549

mishamx/caddy repository overview

⁠caddy-builder

Build Status

Build Caddy with plugins from source using Docker multi-build

⁠Usage

Clone the caddy-builder repository:

$ git clone https://github.com/openfaas/caddy-builder.git
$ cd caddy-builder

Add the Caddy plugins that you want to the plugins.go file:

package caddyhttp

import (
	// http.prometheus
	_ "github.com/miekg/caddy-prometheus"
	// http.ipfilter
	_ "github.com/pyed/ipfilter"
)

Edit the docker-compose⁠ file and replace the image prefix with your own repo name:

version: "3.3"

services:
  caddy:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        CADDY_VERSION: ${CADDY_VERSION:-0.10.9}
    image: openfaas/caddy:${CADDY_VERSION:-0.10.9}
    container_name: caddy
    ports:
      - 80:80
      - 443:443
      - 9180:9180

Build the image with Docker Compose:

CADDY_VERSION=0.10.9 docker-compose build caddy

Run Caddy container exposing 80, 443 and 9180 ports:

docker-compose up -d

Remove the container, www volume and image:

docker-compose down -v --rmi all
⁠Running Caddy with Docker

The openfaas/caddy⁠ comes with a default Caddyfile that you can override by mounting your own config:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -p 80:80 \
    openfaas/caddy

Mount your site root using the www volume:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/site:/www \
    -p 80:80 \
    openfaas/caddy

Expose the Prometheus metric endpoint on http://localhost:9180/metrics:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/site:/www \
    -p 80:80 -p 9180:9180 \
    openfaas/caddy

In your Caddyfile configure the http.prometheus plugin:

example.com {
    prometheus 0.0.0.0:9180
    log stdout
    errors stderr
}

Persist Let's Encrypt certificates on host:

$ docker run -d --name caddy \
    -v $(pwd)/Caddyfile:/etc/caddy/Caddyfile \
    -v $(pwd)/certs:/.caddy \
    -p 80:80 -p 443:443 \
    openfaas/caddy

In your Caddyfile configure the tls email:

example.com {
    tls [email protected]
}
⁠Running Caddy with Docker Swarm

In order to deploy Caddy with a custom config on Docker Swarm, you need to use Docker engine version 17.06 or later. The Caddy image has curl installed so you can easily define a health check:

version: "3.3"

configs:
  caddy_config:
    file: ./Caddyfile

volumes:
  certs: {}

services:
  caddy:
    image: openfaas/caddy
    ports:
      - 80:80
      - 443:443
    configs:
      - source: caddy_config
        target: /etc/caddy/Caddyfile
    volumes:
      - certs:/.caddy
    deploy:
      mode: replicated
      replicas: 1    
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 5s
      timeout: 1s
      retries: 3
⁠License

The caddy-builder is MIT licensed and the Caddy source code⁠ is Apache 2.0 licensed. Because openfaas/caddy is built from source, it's not subject to the EULA⁠ for Caddy's official binary distributions. If you plan to use Caddy for commercial purposes you should run the official Caddy distribution.

Tag summary

Content type

Image

Digest

Size

9 MB

Last updated

almost 8 years ago

docker pull mishamx/caddy