-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
46 lines (32 loc) · 1.32 KB
/
Dockerfile
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
# ====== Stage 1: Builder ======
ARG GOLANG_VERS=1.23
ARG ALPINE_VERS=3.21
FROM golang:${GOLANG_VERS}-alpine${ALPINE_VERS} AS builder
# Set environment variables
ENV CGO_ENABLED=0 \
PLUGIN_PRIO=50 \
COREDNS_VERS=1.12.0
# Install build dependencies
RUN apk update && apk add --no-cache build-base git make binutils ca-certificates && update-ca-certificates
# Clone the CoreDNS repository
RUN git clone --branch v${COREDNS_VERS} https://github.com/coredns/coredns.git --depth=1 /go/src/github.com/coredns/coredns
# Change to the CoreDNS directory
WORKDIR /go/src/github.com/coredns/coredns
# Add the plugin configuration file
ADD plugin.cfg plugin.cfg
# Generate code and build CoreDNS
RUN make gen all
# Install binutils to use 'strip' for reducing binary size and strip the binary
RUN strip -v /go/src/github.com/coredns/coredns/coredns
# ====== Stage 2: Final Image ======
FROM alpine:${ALPINE_VERS}
# Copy CA certificates from the builder stage to support HTTPS
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
# Copy the CoreDNS binary from the builder stage
COPY --from=builder /go/src/github.com/coredns/coredns/coredns /usr/local/bin/coredns
ADD Corefile /etc/Corefile
# Expose DNS ports (both TCP and UDP)
EXPOSE 15353 15353/udp
# Set the entrypoint to the CoreDNS binary
ENTRYPOINT ["coredns"]
CMD ["-conf", "/etc/Corefile"]