[WIP] ns3のDockerfileを書いた

Created 2018年6月28日17:32
Updated 2018年7月6日11:22
Categories Docker ns3

ns3を使う機会がありまして、ビルドするのに依存関係ありまくりそうだったのでDockerイメージ化できればと思い、Dockerfileを書いてみました。

なお、ns3のシミュレーションはc++ではなくpythonで書きたいという前提で作業を行っています。

環境

  • Windows 10 Pro 1803 64bit
  • Docker 18.03.1-ce

作業

aptで死ぬほどパッケージを取ってきますので、sources.listをより速いミラーサーバーに変更しています。

Dockerfileと同じディレクトリに以下の内容でsources.listファイルを用意してください。

deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-backports main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted universe multiverse

Dockerfileは以下のようにします。

FROM ubuntu:16.04

COPY sources.list /etc/apt/sources.list
RUN apt update
RUN apt-get -y install build-essential python3 python3-dev python3-venv git mercurial libgoocanvas-dev \
        openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar uncrustify doxygen \
        graphviz imagemagick texlive texlive-extra-utils texlive-latex-extra texlive-font-utils \
        texlive-lang-portuguese dvipng dia gsl-bin libgsl2 libgsl-dev flex bison libfl-dev tcpdump \
        sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev cmake libc6-dev libc6-dev-i386 libclang-dev \
        libgtk2.0-0 libgtk2.0-dev vtun lxc libboost-signals-dev libboost-filesystem-dev libgraphviz-dev \
        pkg-config
RUN python3 -m venv /venv
RUN bash -c "source /venv/bin/activate && \
    pip install -U pip && \
    pip install wheel && \
    pip install cxxfilt sphinx ipython pygraphviz"
RUN hg clone http://code.nsnam.org/ns-3-allinone
WORKDIR /ns-3-allinone
RUN bash -c "source /venv/bin/activate && \
    python ./download.py -n ns-3.28 && \
    python ./build.py --enable-examples --enable-tests"

WORKDIR /ns-3-allinone/ns-3.28
CMD bash -c "source /venv/bin/activate && ./waf shell"

続いてdocker build -t ns3_ubuntu .を実行してビルドを行います。

終わったら、

$ docker run -it --rm ns3_ubuntu
(venv) python examples/tutorial/first.py
At time 2s client sent 1024 bytes to 10.1.1.2 port 9
At time 2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time 2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
At time 2.00737s client received 1024 bytes from 10.1.1.2 port 9

こんな感じでサンプルが実行できるようになります。

まだまだ知見が無くビルドオプションも適当なので修正すべき点があるかもしれません。

ある程度しっかり使える感じになったらリポジトリでも作ろうかと思います。

参考

コメントを投稿

コメント