Build Snabb in Docker Container on OS/X

Build Snabb in Docker Container on OS/X

Docker for OS/X beta was announced end of March 2016 and I signed up for it, curious to see what I can do with it on a Macbook Air 13″ I travel with frequently.
Well, turns out its pretty useful. I can prototype with Snabb, compile and run it, all without network connectivity if unavailable.

Docker on OS/X

Installation was straightforward, just double click the Docker icon from within the downloaded image. It auto-starts and places a Docker icon in the menu bar. The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS/X. Its possible to adjust the default settings for virtual CPU’s and memory using the Advanced Docker Settings (which I adjusted to 5GB from the 2GB default value):
title

“hello world” or “uname” test

With Docker Engine running, there is always an instance of Alpine Linux active on top of xhyve, but it doesn’t seem to eat much resources when idle, at least I didn’t notice…
Now a quick test in running a single command in a (previously downloaded) ubuntu container:

mwiget-mba13:~ mwiget$ time docker run --name ubuntu -ti --rm ubuntu:14.04.4 uname -a
Linux f5e7539491db 4.4.11-moby #1 SMP Mon May 23 20:46:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
        0.77 real         0.01 user         0.01 sys
mwiget-mba13:~ mwiget$

Not bad: From OS/X to Ubuntu and back in less than a second ;-).

Building and running Snabb in a Container

While I could run an Ubuntu based VM in Virtualbox or commercial hypervisors for OS/X, I wanted to see whats needed to do basic development on Snabb on OS/X with help from a Docker Container. Turns out its pretty simple.

First the Dockerfile:

$ cat Dockerfile
FROM ubuntu:14.04.4
MAINTAINER Marcel Wiget

# Install just enough packages to compile snabb
RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential git
CMD ["/bin/bash", "-c","cd /u && exec /bin/bash"]

Nothing special so far, the Dockerfile downloads the minimal required tools to build Snabb, then executes a bash shell in /u, which is the snabb directory from the host OS/X at runtime (see further down on how to run it).

Build the Container:

docker build -t marcelwiget/build .
Sending build context to Docker daemon  5.12 kB
Step 1 : FROM ubuntu:14.04.4
 ---> 90d5884b1ee0
Step 2 : MAINTAINER Marcel Wiget
 ---> Using cache
 ---> 3ec85a04ecd8
Step 3 : RUN apt-get update
 ---> Using cache
 ---> a2f016854919
Step 4 : RUN apt-get install -y --no-install-recommends build-essential git
 ---> Using cache
 ---> 3eb24f23e3e2
Step 5 : CMD /bin/bash -c cd /u && exec /bin/bash
 ---> Using cache
 ---> e981b7370180
Successfully built e981b7370180
 
Checking the created Container:
$ docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
marcelwiget/build       latest              e981b7370180        About an hour ago   358.8 MB
alpine                  latest              13e1761bf172        3 weeks ago         4.797 MB
ubuntu                  14.04.4             90d5884b1ee0        3 weeks ago         188 MB

Now I have a cloned Snabb repository in the directory ‘snabb’ on OS/X, then launch the build container. Once the shell is loaded, I can simply build snabb via ‘make’.

docker run --name build -ti --rm -v $PWD/snabb:/u marcelwiget/build
root@beeb3c4a0803:/u# make

Once built, I can run snabb:

root@beeb3c4a0803:/u# src/snabb
Usage: src/snabb <program> ...

This snabb executable has the following programs built in:
  example_replay
  example_spray
  firehose
  gc
  lwaftr
  packetblaster
  snabbmark
  snabbnfv
  snabbvmx
  snsh
  top

For detailed usage of any program run:
  snabb <program> --help

If you rename (or copy or symlink) this executable with one of
the names above then that program will be chosen automatically.
root@beeb3c4a0803:/u# md5sum src/snabb
9cd260aba584ca439af59b3167ebfb73  src/snabb

Because the cloned snabb directory ‘snabb’ is mounted into the running Container under /u, the built src/snabb app is also available from the the OS/X host OS:

$ ls -l snabb/src/snabb
-rwxr-xr-x  1 mwiget  1386261502  2495806 May 28 14:16 snabb/src/snabb
mwiget-mba13:snabb-l2tpv3 mwiget$ md5 snabb/src/snabb
MD5 (snabb/src/snabb) = 9cd260aba584ca439af59b3167ebfb73

If I no longer need the Container, I simply quit the shell and the container is stopped and removed (thanks to ‘–rm’).

root@545640d59714:/u# exit
exit
$
Advertisements

One thought on “Build Snabb in Docker Container on OS/X

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: