The official caddy image fares well as long as no additional modules have to be compiled, at which point, a custom image has to be built. Fortunately, caddy maintains an official build image that can be used to build caddy along with the required modules. Sometimes however, the caddy modules themselves are ahead of the official build image in terms of dependencies, including the Go language version, such that either downgrading and building against an earlier version of the module or creating a custom caddy build image are the only options.
The following page contains a custom caddy build image built on top of Debian latest (slim) and will:
xcaddy
, and,caddy
along with any required modules
The Dockerfile
should more than likely be modified in order to swap out or add caddy modules. The very last sequence before removing the temporary directory contains the following command line call to xcaddy
:
xcaddy build \ --with github.com/caddy-dns/cloudflare \ --with github.com/greenpau/caddy-security \ --with github.com/caddy-dns/duckdns \ --output /usr/local/bin/caddy
that should be altered to either remove or add modules as desired. The last parameter –output
tells xcaddy
to place the caddy
binary itself at /usr/local/bin/caddy
.
Building is a matter of issuing:
docker build -t TAG .
where:
TAG
represents a tag to set on the built image (ie: redis:latest
)
After caddy is built, a container can be created and ran either via docker run
or deployed within the swarm with docker stack deploy
.
Note that if the image is to be deployed to a swarm, then more than likely the image should be committed to a local registry serving the local docker swarm.
FROM debian:stable-slim # update package manager RUN apt-get update -y && \ apt-get upgrade -y && \ apt-get dist-upgrade -y && \ apt-get -y autoremove && \ apt-get clean # install required packages RUN apt-get install -y \ curl # create a temporary directory to delete later RUN mkdir -p /tmp/kitchen WORKDIR /tmp/kitchen # install xcaddy and caddy RUN curl -fsSL "https://go.dev/dl/$(curl -s 'https://go.dev/VERSION?m=text' | head -1).linux-amd64.tar.gz" -o go.tar.gz && \ tar -xzf go.tar.gz && \ rm go.tar.gz && \ export PATH=$PATH:/tmp/kitchen/go/bin && \ echo "Installing xcaddy..." && \ GOBIN=/tmp/kitchen/go/bin go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest && \ export XCADDY_WHICH_GO=/tmp/kitchen/go/bin/go && \ echo "Building caddy..." && \ xcaddy build \ --with github.com/caddy-dns/cloudflare \ --with github.com/greenpau/caddy-security \ --with github.com/caddy-dns/duckdns \ --output /usr/local/bin/caddy # remote temporary directory RUN rm -rf /tmp/kitchen ENTRYPOINT [ "/usr/local/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile" ]
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.