-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
50 lines (38 loc) · 1.53 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
47
48
49
50
FROM golang:1.22.7-bookworm AS build
RUN apt-get update && \
apt-get install -y --no-install-recommends bison flex && \
rm -r /var/lib/apt/*
WORKDIR /build
ENV LIBPCAP_VERSION=1.10.5
RUN wget http://www.tcpdump.org/release/libpcap-${LIBPCAP_VERSION}.tar.gz && \
tar xvf libpcap-${LIBPCAP_VERSION}.tar.gz && \
cd libpcap-${LIBPCAP_VERSION} && \
./configure && \
make
COPY cmd/* /build
ENV LD_LIBRARY_PATH="-L/build/libpcap-${LIBPCAP_VERSION}" \
CGO_LDFLAGS="-L/build/libpcap-${LIBPCAP_VERSION}" \
CGO_CPPFLAGS="-I/build/libpcap-${LIBPCAP_VERSION}"
ARG TARGETOS TARGETARCH
RUN --mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "-linkmode 'external' -extldflags '-static' -s -w" -o bin/iptables-tracer .
####################
FROM alpine:3.20 AS final
WORKDIR /bin
COPY --from=build /build/bin/iptables-tracer /bin/
RUN <<EOF
# iptables provides libxt_bpf.so, and iptables-legacy provides the legacy iptables
# binary.
apk add --no-cache iptables iptables-legacy
# Then delete iptables symlink (it points to iptables-nft), and replace it with
# a link to the legacy version.
rm /sbin/iptables /sbin/ip6tables
ln -s /sbin/iptables-legacy /sbin/iptables
ln -s /sbin/ip6tables-legacy /sbin/ip6tables
rm /sbin/iptables-save /sbin/ip6tables-save
ln -s /sbin/iptables-legacy-save /sbin/iptables-save
ln -s /sbin/ip6tables-legacy-save /sbin/ip6tables-save
EOF
COPY modprobe.sh /usr/sbin/modprobe
ENTRYPOINT ["iptables-tracer"]