PLC Directory over DNS (experiment)
at main 1.1 kB view raw
1# Dockerfile 2FROM golang:1.21-alpine AS builder 3 4# Install build dependencies 5RUN apk add --no-cache git ca-certificates tzdata 6 7# Set working directory 8WORKDIR /app 9 10# Copy go mod files 11COPY go.mod go.sum ./ 12 13# Download dependencies 14RUN go mod download 15 16# Copy source code 17COPY . . 18 19# Build the application 20RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o plcdns . 21 22# Final stage 23FROM scratch 24 25# Copy CA certificates from builder 26COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ 27 28# Copy timezone data 29COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo 30 31# Copy the binary 32COPY --from=builder /app/plcdns /plcdns 33 34# Expose DNS ports (UDP and TCP) 35EXPOSE 53/udp 36EXPOSE 53/tcp 37 38# Set default environment variables 39ENV DNS_PORT=53 40 41# Run as non-root user (note: for port 53, container must run with --cap-add=NET_BIND_SERVICE) 42USER 65534:65534 43 44# Health check 45HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ 46 CMD ["/plcdns", "-h"] || exit 1 47 48# Run the application 49ENTRYPOINT ["/plcdns"]