This document contains information on the usage of Docker with CCN-lite. Additionally, it provides guidelines on how to build your own CCN-lite Docker container.
Running a CCN-lite relay inside a Docker container can help keeping your system clean and makes it possible to run several nodes on fully isolated system processes.
The CCN-lite repository on Docker Hub contains a number of tags corresponding to different branches/tags:
| tag name | GitHub branch/tag |
|---|---|
latest |
master |
dev |
dev-master |
0.3.0 |
0.3.0 |
0.2.0 |
0.2.0 |
CCN-lite for Docker obviously requires a working Docker installation. For more information, visit the installation instructions of Docker.
-
Choose a tag of the CCN-lite Docker image (see above) by defining a variable
$img. To use the newest release, use tag0.3.0:img="cnuofbasel/ccn-lite:0.3.0"To use the newest development version, use
dev:img="cnuofbasel/ccn-lite:dev" -
Define additional environment variables and aliases:
UNAME_OS=$(uname -s 2> /dev/null || echo not) if [ "$UNAME_OS" = "Linux" ]; then sudo="sudo"; else sudo=""; fi alias drun="$sudo docker run"
$sudoenables the conditional usage ofsudoon Linux machines without enabling it on OS X.drunis an alias to run Docker containers. -
Pull the Docker image from Docker Hub:
$sudo docker pull $img
-
Run the container:
drun -p 9000:9000/udp --name ccnl $imgOption
-pconnects the internal Docker port to the external port of the host machine. If you need multiple ports exposed, specify-pmultiple times.--nameassigns the running container a named handle; without the flag a random name is chosen. A given name makes it easier to access the container and stop/remove it.To run the container in the background, add option
-d.Without any additional arguments, Docker runs the default command specified by
CMDin the Dockerfile: A CCN-lite NFN relay on port9000with suitendn2013and logging set totrace. To run a custom command (for example using another suite), pass the command line arguments after the container name:drun -p 9000:9000/udp --name ccnl $img ccn-nfn-relay -v trace -u 9000 -d test/cistlv -s cisco2015 -
Test if the container is running correctly by requesting a content object:
HOST_IP=$(ifconfig docker0 | sed -n 's/.*inet addr:\(.*\) Bcast.*/\1/p') drun $img ccn-lite-peek -s ndn2013 -u $HOST_IP/9000 /ndn/simple | drun -i $img ccn-lite-pktdump
Notice that the Docker container of
ccn-lite-peekconnects to port 9000 of the host. All Docker containers are run in an isolated network environment and only connected to the host via the virtual network devicedocker0. In order to access the host from inside a container, we need to obtain the host's IP address, listed indocker0($HOST_IP).To redirect the output of
ccn-lite-peektoccn-lite-pktdump, we need to pass option-i.-ienables an interactive mode so thatccn-lite-pktdumpcan read from the host'sstdin. -
Stop the container (
stop) and remove it (rm). This might take some seconds.$sudo docker stop ccnl && $sudo docker rm ccnl
The Dockerfile is set up in such a way that all CCN-lite command line utilities are directly accessible. For example you can create a content object using ccn-lite-mkC. ccn-lite-mkC reads from stdin, so type something and then press Return:
drun -i $img ccn-lite-mkC -s ndn2013 /ndn/mycontent > mycontent.ndtlvYou can verify the content object by passing it to ccn-lite-pktdump:
drun -i $img ccn-lite-pktdump < mycontent.ndtlvIn order to debug the container, the following commands might prove useful:
-
$sudo docker pslists the running containers. Add option-ato see all containers. -
$sudo docker logs ccnlfetches the output of the CCN-lite containerccnl. -
$sudo docker exec -i -t ccnl /bin/bashstarts a Bash shell inside the containerccnl. -
drun -i -t --name ccnl $img /bin/bashstarts a Bash shell in a new containerccnl.
In order to build your own CCN-lite Docker image, follow the UNIX installation instructions to set up the CCN-lite sources (in particular Dockerfile) and relevant environment variables.
Then, use docker build (do not forget to put the . at the end):
cd $CCNL_HOME
$sudo docker build -t "<your-name>/ccn-lite:dev" .<your-name> usually refers to your Docker Hub username. If you are not using Docker Hub, you can choose a name freely (for
example your user account name).