You might have to install static versions of standard libraries
sudo dnf -y install glibc-static
For this build we are trying to pick and choose the exact DPDK libraries our app requires. We are also choosing which NICs we want to support.
cmake_minimum_required(VERSION 2.8)
SET(PRJ l2fwd)
PROJECT(${PRJ})
SET(SOURCE_EXE main.c)
SET(CMAKE_C_FLAGS "-Wall -Wextra -g -O3 -std=gnu11")
SET(CMAKE_EXE_LINKER_FLAGS "-static")
if(DEFINED ENV{RTE_SDK})
message("-- Using DPDK: $ENV{RTE_SDK}")
INCLUDE_DIRECTORIES($ENV{RTE_SDK}/build/include)
LINK_DIRECTORIES($ENV{RTE_SDK}/build/lib)
else()
message(FATAL_ERROR "RTE_SDK is NOT defined")
endif()
SET(DPDK_INFRA
"-lrte_mbuf -lrte_eal -lrte_mempool -lrte_ring -lrte_ethdev \
-lrte_hash -lrte_kvargs")
SET(DPDK_NET
"-lrte_pmd_i40e")
SET(DPDK_LIBS
"-Wl,--whole-archive"
"${DPDK_INFRA} ${DPDK_NET}" # Replace with "-ldpdk" if needed.
"-Wl,--no-whole-archive")
ADD_EXECUTABLE(${PRJ} ${SOURCE_EXE})
TARGET_LINK_LIBRARIES(${PRJ} ${DPDK_LIBS})
TARGET_LINK_LIBRARIES(${PRJ} pthread dl rt m)
Build the app
cmake . && make
[ 50%] Building C object CMakeFiles/l2fwd.dir/main.c.o
[100%] Linking C executable l2fwd
/home/stack/dpdk/build/lib/librte_eal.a(eal_common_options.o): In function `eal_plugins_init':
eal_common_options.c:(.text+0x6c3): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
[100%] Built target l2fwd
Below is the Dockerfile used to create our container. We use Alpine Linux to keep the image size to the minimum, while meeting basic OS requirements needed to run DPDK.
FROM alpine
ADD l2fwd /l2fwd
CMD ["/l2fwd", "-c", "0xf", "--socket-mem", "1024,0", "--", "-p", "0x3"]
We are mounting hugepage mount point of the host into the container. uio0 and uio3 represent the ports bound to igb_uio so we need to mount them too. Privileged flag is no more required (since DPDK 17.05)
docker run -it --device=/dev/uio0 --device=/dev/uio3 --ulimit memlock=-1 -v /dev/hugepages:/dev/hugepages krsna1729/dpdk-l2fwd-bin
EAL: Detected 88 lcore(s)
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL: probe driver: 8086:1572 net_i40e
..........
Similarly with vfio-pci driver. Requires iommu
docker run -it --device=/dev/vfio/48 --device=/dev/vfio/49 --device=/dev/vfio/vfio --ulimit memlock=-1 -v /dev/hugepages:/dev/hugepages krsna1729/dpdk-l2fwd-bin
EAL: Detected 88 lcore(s)
EAL: 16 hugepages of size 1073741824 reserved, but no mounted hugetlbfs found for that size
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: PCI device 0000:05:00.0 on NUMA socket 0
EAL: probe driver: 8086:1572 net_i40e
EAL: using IOMMU type 1 (Type 1)
EAL: Ignore mapping IO port bar(1) addr: 383f
EAL: Ignore mapping IO port bar(4) addr: 383f
PMD: eth_i40e_dev_init(): FW 4.22 API 1.2 NVM 04.02.05 eetrack 800014cc
..........
Multi-stage dockerfile
FROM fedora:26 as dpdk-builder
RUN dnf -y install glibc-static gcc-c++ cmake make xz
ARG DPDK_VER=17.02
ARG DPDK_TARGET=x86_64-native-linuxapp-gcc
ADD http://fast.dpdk.org/rel/dpdk-${DPDK_VER}.tar.xz /opt
WORKDIR /opt
RUN tar -xf dpdk-${DPDK_VER}.tar.xz && mv dpdk-${DPDK_VER} dpdk && cd dpdk && \
sed -ri 's,(IGB_UIO=).*,\1n,' config/common_linuxapp && \
sed -ri 's,(KNI_KMOD=).*,\1n,' config/common_linuxapp && \
make config T=${DPDK_TARGET} && make -j
ENV RTE_SDK /opt/dpdk
RUN mkdir -p /opt/l2fwd && cp ${RTE_SDK}/examples/l2fwd/main.c /opt/l2fwd/
COPY CMakeLists.txt /opt/l2fwd
WORKDIR /opt/l2fwd
RUN cmake . && make
FROM alpine
COPY --from=dpdk-builder /opt/l2fwd/l2fwd /l2fwd
CMD ["/l2fwd", "-c", "0xf", "--socket-mem", "1024,0", "--", "-p", "0x3"]