-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile-static
More file actions
65 lines (51 loc) · 1.67 KB
/
Dockerfile-static
File metadata and controls
65 lines (51 loc) · 1.67 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# ========================
# Stage 1: Build
# ========================
FROM alpine:3.23 AS builder
# 使用国内源
# MIRRORS RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories && apk update
# 设置时区
ARG HOST_TZ=UTC
ENV TZ=$HOST_TZ
# 安装构建工具和静态依赖
RUN apk add --no-cache \
build-base wget upx\
openssl-dev openssl-libs-static \
libevent-dev libevent-static \
zlib-dev zlib-static \
ldns-dev ldns-static \
tzdata \
&& rm -rf /var/cache/apk/*
# 已经在alpine官方提交PR增加ldns静态版,alpine:3.23 以上无需在自行编译
# # 下载ldns发行版
# WORKDIR /src
# RUN wget https://www.nlnetlabs.nl/downloads/ldns/ldns-1.8.3.tar.gz && \
# tar xzf ldns-1.8.3.tar.gz && \
# cd ldns-1.8.3
# # 编译ldns静态版(alpine官方没有提供)
# WORKDIR /src/ldns-1.8.3
# RUN ./configure --enable-static --disable-shared --with-ssl=/usr LDFLAGS="-static" && \
# make -j$(nproc) && \
# make install
# 复制程序源码
WORKDIR /app
COPY /src ./src
COPY /include ./include
# 增加静态标记
RUN sed -i -E 's/^#define[[:space:]]+VERSION[[:space:]]+"([^"]+)"/#define VERSION "\1(static)"/' ./include/config.h
# 编译成静态二进制
RUN gcc -D__TIMEZONE_NAME__='"'"$(date +%Z)"'"' \
-static -O2 -s -o ./docker-dns ./src/*.c \
-I./include -lldns -lssl -lcrypto -levent -lz -lpthread
RUN upx --best --lzma ./docker-dns
# ========================
# Stage 2: Runtime
# ========================
FROM scratch
# 拷贝二进制到运行镜像
COPY --from=builder /app/docker-dns /docker-dns
# 暴露 53/udp 端口
EXPOSE 53/udp
# 设置容器入口
ENTRYPOINT ["/docker-dns"]
CMD ["-f"]