

# First Stage: Builder
FROM docker.io/amd64/almalinux:9 AS builder
# Update and install base tools and repositories
RUN \
dnf -y update && \
dnf -y install epel-release dnf-plugins-core && \
dnf config-manager --set-enabled crb
# Install required development packages
RUN dnf -y install \
autoconf \
automake \
cargo \
cbindgen \
diffutils \
dpdk-devel \
elfutils-libelf-devel \
file \
file-devel \
gcc \
gcc-c++ \
git \
hiredis-devel \
jansson-devel \
jq \
lua-devel \
libbpf-devel \
libtool \
libyaml-devel \
libnfnetlink-devel \
libnetfilter_queue-devel \
libnet-devel \
libcap-ng-devel \
libevent-devel \
libmaxminddb-devel \
libpcap-devel \
libprelude-devel \
libtool \
lz4-devel \
make \
nspr-devel \
nss-devel \
nss-softokn-devel \
numactl-devel \
pcre2-devel \
pkgconfig \
python3-devel \
python3-yaml \
rust \
which \
zlib-devel
# Install Hyperscan for x86_64
RUN if [ "$(arch)" = "x86_64" ]; then \
dnf -y install https://kojipkgs.fedoraproject.org/packages/hyperscan/5.4.0/4.el9/x86_64/hyperscan-5.4.0-4.el9.x86_64.rpm https://kojipkgs.fedoraproject.org/packages/hyperscan/5.4.0/4.el9/x86_64/hyperscan-devel-5.4.0-4.el9.x86_64.rpm; \
fi
# Set version argument and working directory
ARG VERSION
WORKDIR /src
# Clone or download the Suricata source code
RUN if [ "${VERSION}" = "master" ]; then \
git clone https://github.com/OISF/suricata.git suricata-${VERSION}; \
git clone https://github.com/OISF/libhtp.git suricata-${VERSION}/libhtp; \
(cd suricata-${VERSION}/suricata-update && \
curl -L https://github.com/OISF/suricata-update/archive/master.tar.gz | tar zxf - --strip-components=1); \
(cd suricata-${VERSION} && ./autogen.sh); \
else \
curl -OL https://www.openinfosecfoundation.org/download/suricata-${VERSION}.tar.gz; \
tar zxf suricata-${VERSION}.tar.gz; \
fi
# Change to the Suricata directory
WORKDIR /src/suricata-${VERSION}
# Configure build arguments and compile options
ARG CONFIGURE_ARGS
RUN ./configure \
--prefix=/usr \
--disable-shared \
--disable-gccmarch-native \
--enable-lua \
--enable-nfqueue \
--enable-hiredis \
--enable-geoip \
--enable-ebpf \
--enable-dpdk \
${CONFIGURE_ARGS}
# Set number of cores for compilation
ARG CORES=2
RUN make -j "${CORES}"
# Install Suricata to a temporary directory
RUN make install install-conf DESTDIR=/fakeroot
# Clean up unnecessary directories
RUN rm -rf /fakeroot/var
# Second Stage: Runner
FROM docker.io/almalinux/amd64:9-base AS runner
# Update and install runtime dependencies
RUN \
dnf -y update && \
dnf -y install epel-release && \
dnf -y install \
cronie \
dpdk \
elfutils-libelf \
file \
findutils \
hiredis \
iproute \
jansson \
lua-libs \
libbpf \
libyaml \
libnfnetlink \
libnetfilter_queue \
libnet \
libcap-ng \
libevent \
libmaxminddb \
libpcap \
libprelude \
logrotate \
lz4 \
net-tools \
nss \
nss-softokn \
numactl \
pcre2 \
procps-ng \
python3 \
python3-yaml \
tcpdump \
which \
zlib && \
if [ "$(arch)" = "x86_64" ]; then dnf -y install https://kojipkgs.fedoraproject.org/packages/hyperscan/5.4.0/4.el9/x86_64/hyperscan-5.4.0-4.el9.x86_64.rpm; fi && \
dnf clean all && \
find /etc/logrotate.d -type f -not -name suricata -delete
# Copy built files from the builder stage
COPY --from=builder /fakeroot /
# Create necessary directories
RUN mkdir -p /var/log/suricata /var/run/suricata /var/lib/suricata
# Copy configuration files
COPY /update.yaml /etc/suricata/update.yaml
COPY /suricata.logrotate /etc/logrotate.d/suricata
# Update Suricata sources and enable features
RUN suricata-update update-sources && \
suricata-update enable-source oisf/trafficid && \
suricata-update --no-test --no-reload && \
/usr/bin/suricata -V
# Create Suricata user and set permissions
RUN useradd --system --create-home suricata && \
chown -R suricata:suricata /etc/suricata && \
chown -R suricata:suricata /var/log/suricata && \
chown -R suricata:suricata /var/lib/suricata && \
chown -R suricata:suricata /var/run/suricata && \
cp -a /etc/suricata /etc/suricata.dist && \
chmod 600 /etc/logrotate.d/suricata
# Define volumes
VOLUME /var/log/suricata
VOLUME /var/lib/suricata
VOLUME /etc/suricata
# Copy the entrypoint script and set as the entrypoint
COPY /docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
# Verify the Suricata build
RUN /usr/bin/suricata --build-info
이 단계는 Suricata 소프트웨어를 빌드하는 데 필요한 도구 및 라이브러리를 설치하고 Suricata를 컴파일합니다.
FROM docker.io/amd64/almalinux:9 AS builder
amd64 아키텍처 기반 이미지를 사용하여 빌드 환경을 생성합니다.RUN \
dnf -y update && \
dnf -y install epel-release dnf-plugins-core && \
dnf config-manager --set-enabled crb
dnf update: 시스템 패키지를 최신 버전으로 업데이트.epel-release: 추가 패키지들을 설치할 수 있도록 EPEL(Extra Packages for Enterprise Linux) 저장소를 활성화.crb(CodeReady Builder): 추가 개발 도구를 위한 저장소 활성화.RUN dnf -y install ...
autoconf, automake: 자동화된 빌드 환경 설정.gcc, gcc-c++: C/C++ 컴파일러.dpdk-devel, libpcap-devel: 네트워크 관련 라이브러리.rust, cargo: Rust 기반 코드 빌드.python3-devel: Python 3 지원.RUN if [ "$(arch)" = "x86_64" ]; then \
dnf -y install https://kojipkgs.fedoraproject.org/...; \
fi
ARG VERSION
WORKDIR /src
RUN if [ "${VERSION}" = "master" ]; then \
git clone https://github.com/OISF/suricata.git ...; \
else \
curl -OL https://www.openinfosecfoundation.org/...; \
tar zxf suricata-${VERSION}.tar.gz; \
fi
master 브랜치를 사용할 경우, Git 리포지토리에서 최신 소스를 클론.RUN ./configure \
--prefix=/usr \
--disable-shared ...
./configure: Suricata 빌드 환경을 설정합니다.--prefix: 설치 경로 지정.--enable-lua: Lua 스크립팅 지원.--enable-dpdk: DPDK(고속 패킷 처리) 지원.ARG CORES=2
RUN make -j "${CORES}"
RUN make install install-conf DESTDIR=/fakeroot
make: 소스 코드를 빌드합니다.make install: 빌드된 파일을 /fakeroot 디렉토리에 임시로 설치합니다.RUN rm -rf /fakeroot/var
/var 디렉토리 관련 문제가 발생할 수 있으므로 이를 제거합니다.이 단계는 Suricata 실행 환경을 생성합니다.
FROM docker.io/almalinux/amd64:9-base AS runner
RUN \
dnf -y update && \
dnf -y install ...
tcpdump, iproute 등).logrotate).COPY --from=builder /fakeroot /
/fakeroot에서 실행 환경으로 복사.RUN mkdir -p /var/log/suricata /var/run/suricata /var/lib/suricata
COPY /update.yaml /etc/suricata/update.yaml
COPY /suricata.logrotate /etc/logrotate.d/suricata
RUN suricata-update update-sources ...
RUN useradd --system --create-home suricata ...
suricata-update: 서명 데이터베이스를 업데이트.useradd: Suricata 실행 전용 시스템 사용자 생성.VOLUME /var/log/suricata
VOLUME /var/lib/suricata
VOLUME /etc/suricata
COPY /docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
RUN /usr/bin/suricata --build-info
이 Dockerfile은 빌드 단계와 실행 단계로 나뉘며, AlmaLinux를 기반으로 Suricata를 빌드 및 실행할 수 있는 컨테이너 이미지를 만듭니다.
빌드 단계에서 소스를 컴파일하고, 실행 단계에서 필요한 환경을 설정합니다.