-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (36 loc) · 1.08 KB
/
Dockerfile
File metadata and controls
50 lines (36 loc) · 1.08 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
# Multi-stage build for C++20 DNS server
# Build stage
FROM ubuntu:24.04 AS builder
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
# Copy source files
COPY CMakeLists.txt .
COPY include/ include/
COPY src/ src/
COPY tests/ tests/
# Build release binary
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF \
&& cmake --build build --parallel
# Runtime stage
FROM ubuntu:24.04 AS runtime
RUN apt-get update && apt-get install -y \
libstdc++6 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -s /bin/false dnsserver
WORKDIR /app
# Copy binary from builder
COPY --from=builder /build/build/dns_server /app/dns_server
# Copy entrypoint script
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh
# DNS uses UDP port 53
EXPOSE 53/udp
# Run as root for port 53 binding (required for privileged ports)
# Use --cap-add=NET_BIND_SERVICE in production for non-root binding
USER root
ENTRYPOINT ["/app/docker-entrypoint.sh"]