Skip to content

Commit c87729f

Browse files
committed
added multistage docker builds with docker instructions in readme
1 parent 63e5f9f commit c87729f

File tree

4 files changed

+89
-60
lines changed

4 files changed

+89
-60
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ See __--enable-jnat__ below
137137
The toolset is build upon the autotools framework. Run `./autogen.sh` first.
138138
Afterwards `./configure` `make` and `make install` should do the trick.
139139

140+
### Docker
141+
142+
> These commands assume the current working directory is the root of the nfdump repository
143+
144+
To build and run the `nfcapd` target (runs `nfcapd` by default):
145+
146+
```
147+
docker build -t nfcapd --target nfcapd -f extra/docker/Dockerfile .
148+
mkdir -p /tmp/flows
149+
docker run -it --rm --name=nfcapd -p 9995:9995/udp -v /tmp/flows:/data nfcapd
150+
```
151+
152+
Desired arguments to `nfcapd` can be appended to the `docker run` command above.
153+
154+
To build the `nfdump` target (drops you into an interactive shell by default):
155+
156+
```
157+
docker build -t nfdump --target nfdump -f extra/docker/Dockerfile .
158+
mkdir -p /tmp/flows
159+
docker run -it --rm --name=nfdump -v /tmp/flows:/data nfdump
160+
```
161+
162+
For reference, there is also an Ubuntu Dockerfile at _extra/docker/Dockerfile.ubuntu_ with similar `nfcapd` and `nfdump` targets.
163+
164+
### Older Linux-distribution notes
165+
140166
For various older Linuxes need a more modern compiler:
141167

142168
#### CentOS 7.x:

extra/docker/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ARG ALPINE_VERSION=3
2+
FROM alpine:${ALPINE_VERSION} AS builder
3+
4+
# Assume context is root of nfdump repository
5+
COPY . /app
6+
RUN apk add --no-cache build-base gcc abuild binutils make \
7+
libtool bzip2-dev libpcap-dev flex bison \
8+
autoconf automake m4 pkgconfig
9+
10+
WORKDIR /app
11+
12+
RUN ./autogen.sh \
13+
&& ./configure --enable-maxmind --enable-nfpcapd --enable-sflow=yes \
14+
&& make && make install
15+
16+
FROM alpine:${ALPINE_VERSION} AS base
17+
18+
VOLUME /data
19+
RUN apk add --no-cache bzip2-dev \
20+
&& mkdir -p /data
21+
22+
COPY --from=builder /usr/local /usr/local
23+
24+
FROM base AS nfcapd
25+
26+
EXPOSE 9995/udp
27+
28+
ENTRYPOINT ["/usr/local/bin/nfcapd"]
29+
30+
CMD ["-w", "/data", "-S", "1", "-y", "-p", "9995"]
31+
32+
FROM base AS nfdump
33+
34+
ENTRYPOINT ["/bin/ash"]

extra/docker/Dockerfile.alpine

Lines changed: 0 additions & 31 deletions
This file was deleted.

extra/docker/Dockerfile.ubuntu

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#
2-
# Example Ubuntu Dockerfile
2+
# Reference Ubuntu Dockerfile
33
#
44

5-
# Pull base image.
6-
FROM ubuntu:latest
5+
ARG UBUNTU_VERSION=24.04
6+
FROM ubuntu:${UBUNTU_VERSION} AS builder
77

8-
ARG NFDUMP_VERSION=1.7.3
8+
# Assume context is root of nfdump repository
9+
COPY . /app
910

10-
#Expose netflow port
11-
EXPOSE 9995/udp
12-
13-
# Install.
11+
# Install dependencies
1412
RUN apt-get update && apt-get install -y \
1513
wget \
1614
unzip \
@@ -26,30 +24,32 @@ RUN apt-get update && apt-get install -y \
2624
flex \
2725
make \
2826
libpcap-dev \
29-
libbz2-dev &&
30-
rm -rf /var/lib/apt/lists/*
27+
libbz2-dev \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
WORKDIR /app
31+
RUN ./autogen.sh \
32+
&& ./configure --enable-nfpcapd --enable-maxmind --enable-sflow \
33+
&& make && make install \
34+
&& ldconfig
35+
36+
FROM ubuntu:${UBUNTU_VERSION} AS base
3137

32-
RUN cd /usr/src &&
33-
wget https://github.com/phaag/nfdump/archive/refs/tags/v$NFDUMP_VERSION.tar.gz &&
34-
tar xfz v$NFDUMP_VERSION.tar.gz &&
35-
cd nfdump-$NFDUMP_VERSION &&
36-
./autogen.sh &&
37-
./configure --enable-nfpcapd --enable-maxmind --enable-sflow &&
38-
make &&
39-
make install
38+
COPY --from=builder /usr/local /usr/local
39+
RUN apt-get update && apt-get install -y libbz2-dev \
40+
&& rm -rf /var/lib/apt/lists/*
4041

41-
RUN ldconfig
42+
VOLUME /data
43+
RUN mkdir -p /data
44+
45+
FROM base AS nfcapd
46+
47+
EXPOSE 9995/udp
4248

43-
# Add files.
44-
#ADD root/.bashrc /root/.bashrc
45-
#ADD root/.gitconfig /root/.gitconfig
46-
#ADD root/.scripts /root/.scripts
49+
ENTRYPOINT ["/usr/local/bin/nfcapd"]
4750

48-
# Set environment variables.
49-
#ENV HOME /root
51+
CMD ["-w", "/data", "-S", "1", "-y", "-p", "9995"]
5052

51-
# Define working directory.
52-
WORKDIR /usr/src
53+
FROM base AS nfdump
5354

54-
# Define default command.
55-
CMD ["bash"]
55+
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)