1. The problem I’m having:
I want to build a minimal caddy image for a small static site server deployed in kubernetes. I’ve previously used xcaddy
, but it adds a lot of stuff I don’t need. I’ve been looking through the caddy modules, but aren’t quite sure which once I actually need.
These are the modules I think I need:
- “github.com/caddyserver/caddy/v2/caddyconfig/caddyfile”
- “github.com/caddyserver/caddy/v2/modules/caddyhttp/standard”
- “github.com/caddyserver/caddy/v2/modules/logging”
- “github.com/caddyserver/caddy/v2/modules/metrics”
I’m not sure if the caddy-events
modules are needed?
Also, I don’t need everything from caddyhttp
, but it’s not clear to me which (maybe apart from the reverseproxy
module) I can leave out.
Everything to do with https/certificates etc. I can leave out, as this is handled by other parts of my cluster.
I’ve included the metrics
module as I’m using prometheus to scape metrics in my cluster.
2. Error messages and/or full log output:
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
a. System environment:
- Building from scratch image for linux/amd64
- Kubernetes v1.31.1
c. Service/unit/compose file:
This is my current Dockerfile (using xcaddy):
# use Go as Builder
FROM golang:1.23.2 AS builder
RUN mkdir /build
WORKDIR /build
# renovate: datasource=github-tags depName=caddyserver/xcaddy
RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@v0.4.2
ARG GOOS=linux
ARG GOARCH=amd64
# renovate: datasource=github-tags depName=caddyserver/caddy
RUN xcaddy build v2.8.4
# Use the build image
FROM scratch
COPY --from=builder /build/caddy /bin/caddy
WORKDIR /var/www/html
USER 314:314
# add site files
COPY ./public /var/www/html
# add Caddyfile
COPY Caddyfile /var/www/html/Caddyfile
# Set container labels
LABEL caddy-version="2.8.4"
LABEL org.opencontainers.image.source="https://github.com/chrede88/qubtDocker"
LABEL org.opencontainers.image.description="My personal website."
LABEL org.opencontainers.image.licenses="MIT"
# Expose port 8080
EXPOSE 8080
# Expose port 2016 for metrics
EXPOSE 2019
# run binary
ENTRYPOINT ["/bin/caddy"]
CMD ["run"]
d. My complete Caddy config:
{
http_port 8080
auto_https off
admin off
servers {
metrics
}
}
:8080 {
encode zstd gzip
file_server {
}
handle_errors {
@404 {
expression {http.error.status_code} == 404
}
rewrite @404 /404.html
file_server
}
log {
output stdout
}
}
:2019 {
metrics /metrics {
disable_openmetrics
}
}