在Docker中运行DPDK

来源:互联网 发布:校园安全事件网络诈骗 编辑:程序博客网 时间:2024/05/15 10:18

版本

Docker:1.12.1
DPDK:16.07

Docker的安装

在Ubuntu中docker的安装还是很简单的。参考官方文档1就行了。需要注意的是只能在64位,linux版本号不低于3.11.0-15-generic的发行版上运行。所以在OpenVZ的VPS上不能运行。

制造DPDK的Docker镜像

这边主要参考的是网上的一篇博客2和红帽的Github[^2]来写Dockerfile的。Dockerfile如下:

FROM ubuntuMAINTAINER NachtZ<nachtz@outlook.com>LABEL RUN docker run -it --privileged -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages -v /sys/devices/system/node:/sys/devices/system/node -v /dev:/dev --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE"# Setup yum repos, or use subscription-manager# Install DPDK support packages.RUN  apt-get update && apt-get install -y libpcap-dev wget xz-utils gcc automake autoconf libtool make# Build DPDK and pktgen-dpdk for x86_64-native-linuxapp-gcc.WORKDIR /rootCOPY ./build_dpdk.sh /root/build_dpdk.shCOPY ./dpdk-profile.sh /etc/profile.d/#RUN /root/build_dpdk.sh# Defaults to a bash shell, you could put your DPDK-based application here.CMD ["/bin/bash"]

这个Dockerfile的注解如下:
FROM ubuntu:说明该镜像的源镜像是Ubuntu。
MAINTAINER NachtZ<nachtz@outlook.com>:介绍镜像的作者。

LABEL RUN docker run -it --privileged -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages -v /sys/devices/system/node:/sys/devices/system/node -v /dev:/dev --name NAME -e NAME=NAME -e· IMAGE=IMAGE IMAGE": 镜像的标签。

RUN apt-get update && apt-get install -y libpcap-dev wget xz-utils gcc automake autoconf libtool make:安装DPDK所需要的依赖程序,因为在Docker中的系统都是比较精简的,所以很多程序都需要自己安装。

WORKDIR /rootCOPY ./build_dpdk.sh /root/build_dpdk.shCOPY ./dpdk-profile.sh /etc/profile.d/

上面这段话是把Dockerfile同目录下./build_dpdk.sh,./dpdk-profile.sh拷贝到镜像里面去。

CMD ["/bin/bash"]:指定动作是打开一个bash。

到此为止,一个可以用来安装DPDK的镜像就完成了。接下来就是打开它。

在Docker中安装DPDK

在shell中运行:
docker run -it --privileged -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages -v /sys/devices/system/node:/sys/devices/system/node -v /dev:/dev xxx(最后的xxx表示的是之前的镜像的名字)
在运行这个之前,需要将宿主机的DPDK环境都配置好。比如hugepage,以及转载好DPDK驱动的端口。之后运行docker run,

--privileged -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages -v /sys/devices/system/node:/sys/devices/system/node 这段话的意思就是给Docker容器权限来使用宿主机的端口,hugepage等。

之后我们进入到Docker的容器中。
在容器的root目录下可以看到之前拷贝的./build_dpdk.sh。内容如下:

#!/bin/bash##################################################################################  build_dpdk.sh##             - Build DPDK and pktgen-dpdk for ##  Usage:     Adjust variables below before running, if necessary.##  MAINTAINER:  jeder@redhat.com###################################################################################################################################################################  Define Global Variables and Functions################################################################################URL=http://fast.dpdk.org/rel/dpdk-16.04.tar.xzBASEDIR=/rootVERSION=16.04PACKAGE=dpdkDPDKROOT=$BASEDIR/$PACKAGE-$VERSIONCONFIG=x86_64-native-linuxapp-gcc# Download/Build DPDKcd $BASEDIRwget $URLtar -xf $PACKAGE-$VERSION.tar.xzcd $DPDKROOT sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/' ${DPDKROOT}/config/common_linuxapp \  && sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/' ${DPDKROOT}/config/common_linuxapp \  && sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/' ${DPDKROOT}/config/common_linuxapp# don't build unnecessary stuff, can be reversed in dpdk_config.shsed -i 's/CONFIG_RTE_APP_TEST=y/CONFIG_RTE_APP_TEST=n/' ${DPDKROOT}/config/common_base \  && sed -i 's/CONFIG_RTE_TEST_PMD=y/CONFIG_RTE_TEST_PMD=n/' ${DPDKROOT}/config/common_base \  && sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/' ${DPDKROOT}/config/common_base \  && sed -i 's/CONFIG_RTE_LIBRTE_IGB_PMD=y/CONFIG_RTE_LIBRTE_IGB_PMD=n/' ${DPDKROOT}/config/common_base \  && sed -i 's/CONFIG_RTE_LIBRTE_IXGBE_PMD=y/CONFIG_RTE_LIBRTE_IXGBE_PMD=n/' ${DPDKROOT}/config/common_base \make config T=$CONFIGsed -ri 's,(PMD_PCAP=).*,\1y,' build/.configmake config T=$CONFIG install

这个文档来自[^3]。我依照DPDK 16.04中的文档和博客[^2]来改造的。在博客[^2]中提到:

One thing that is important is to not rely on kernel headers; doing so would be seriously non portable. The uio and igb_uio kernel modules have to be built and installed by the host that will run the DPDK container. Therefore, we configure the SDK to not compile kernel modules, and therefore not require installing kernel headers on the build system.

就是说在Docker中,用到的网卡驱动是宿主机的驱动,所以不需要编译网卡内核驱动。在./build_dpdk.sh中,的两行sed语句就是在修改编译配置。

手动运行完./build_dpdk.sh之后,就可以正常编译运行DPDK的程序了。
比如可以:

$:export RTE_SDK=/root/dpdk-16.04$:export RTE_TARGET=x86_64-native-linuxapp-gcc$:cd dpdk-16.04/example/helloworld$:make$:./build/helloworld

就可以看到helloworld正常的运行了。

Github

这是修改完成之后的Docker的Dockerfile和两个sh文件。NachtZ/docker-dpdk

参考资料

  1. Jason的博客[^2]
  2. Redhat的dpdk_docker[^3]

Reference


  1. Docker安装指南
    [^2]:Jason 的博客
    [^3]:Redhat的DPDK_docker ↩
  2. Docker安装指南
    [^2]:Jason 的博客
    [^3]:Redhat的DPDK_docker ↩
0 0
原创粉丝点击