Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active April 21, 2024 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Winand/460615c5c292753279fba99f31c32bdb to your computer and use it in GitHub Desktop.
Save Winand/460615c5c292753279fba99f31c32bdb to your computer and use it in GitHub Desktop.
Build Caddy server Docker image
FROM golang:1.22.2-alpine AS build
ARG XCADDY_VERSION=0.4.0
ARG CADDY_VERSION
RUN apk --no-cache add libcap
RUN wget -O /tmp/xcaddy.tar.gz "https://github.com/caddyserver/xcaddy/releases/download/v${XCADDY_VERSION}/xcaddy_${XCADDY_VERSION}_linux_amd64.tar.gz"; \
echo "$checksum /tmp/xcaddy.tar.gz" | sha512sum -c; \
tar x -z -f /tmp/xcaddy.tar.gz -C /usr/bin xcaddy; \
rm -f /tmp/xcaddy.tar.gz; \
chmod +x /usr/bin/xcaddy;
RUN xcaddy build ${CADDY_VERSION}
RUN setcap cap_net_bind_service=+ep /go/caddy; \
chmod +x /go/caddy; \
/go/caddy version
FROM alpine:3.18
ARG CADDY_VERSION
RUN apk add --no-cache \
ca-certificates \
libcap \
mailcap
RUN set -eux; \
mkdir -p \
/config/caddy \
/data/caddy \
/etc/caddy \
/usr/share/caddy \
; \
wget -O /etc/caddy/Caddyfile "https://github.com/caddyserver/dist/raw/cd39178d252a610fee6aa8465c787d9c780007a2/config/Caddyfile"; \
wget -O /usr/share/caddy/index.html "https://github.com/caddyserver/dist/raw/cd39178d252a610fee6aa8465c787d9c780007a2/welcome/index.html"
# https://github.com/caddyserver/caddy/releases
ENV CADDY_VERSION v${CADDY_VERSION}
COPY --from=build /go/caddy /usr/bin/caddy
# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME /config
ENV XDG_DATA_HOME /data
LABEL org.opencontainers.image.version=v${CADDY_VERSION}
LABEL org.opencontainers.image.title=Caddy
LABEL org.opencontainers.image.description="a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
LABEL org.opencontainers.image.url=https://caddyserver.com
LABEL org.opencontainers.image.documentation=https://caddyserver.com/docs
LABEL org.opencontainers.image.vendor="Light Code Labs"
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source="https://github.com/caddyserver/caddy-docker"
EXPOSE 80
EXPOSE 443
EXPOSE 443/udp
EXPOSE 2019
WORKDIR /srv
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
@Winand
Copy link
Author

Winand commented Apr 19, 2024

Usage:
docker buildx build --build-arg="CADDY_VERSION=fix-default-logger" --no-cache-filter=build -t user/caddy:tag --push .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment