-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (37 loc) · 1.33 KB
/
Dockerfile
File metadata and controls
51 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Multi-stage build for Coraza-Caddy WAF
# --- Versions ---
ARG CADDY_VERSION=2.9.1
ARG CORAZA_VERSION=v2.0.0
# --- Build stage ---
FROM caddy:${CADDY_VERSION}-builder AS builder
ARG CORAZA_VERSION
ENV CORAZA_VERSION=${CORAZA_VERSION}
RUN xcaddy build \
--with github.com/corazawaf/coraza-caddy@${CORAZA_VERSION} \
--with github.com/caddyserver/replace-response
# --- Runtime stage ---
FROM caddy:${CADDY_VERSION}-alpine
ARG CORAZA_VERSION
ENV CORAZA_VERSION=${CORAZA_VERSION}
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
# Create non-root user for security
RUN addgroup -g 1001 -S caddy && \
adduser -u 1001 -S caddy -G caddy
# Create directories with proper permissions
RUN mkdir -p /etc/caddy /var/lib/caddy /var/log/caddy /data/caddy && \
chown -R caddy:caddy /etc/caddy /var/lib/caddy /var/log/caddy /data/caddy
# Copy Caddyfile template
COPY Caddyfile /etc/caddy/Caddyfile
# Install curl for health checks
RUN apk add --no-cache curl
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Switch to non-root user
USER caddy
# Expose ports (8080 = HTTP, 8443 = HTTPS)
EXPOSE 8080 8443
# Set working directory
WORKDIR /var/lib/caddy
# Start Caddy
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]