[Ndn-interest] Dockerfile for NFD on Ubuntu

Felix Rabe felix at rabe.io
Tue Sep 2 14:19:02 PDT 2014


Greetings from around the corner :)

As I see no way to edit that Wiki page (I'm logged in to Redmine), I've 
just written a bit of a writeup about the most important Docker commands 
and how to use the image in the attached file. Feel free to put the 
content on the wiki.

- Felix

On 01/Sep/14 03:38, Alex Afanasyev wrote:
> Cool!
>
> When you have time, can you also write some basic steps on how one would start working with Docker?  For example, on this wiki page: http://redmine.named-data.net/projects/nfd/wiki/Using_NFD_with_Docker?parent=Wiki (I already linked it from main NFD wiki)
>
> I have only read briefly about the Docker and others probably also have very limited knowledge about it.  But from what I get, it could be very convenient way to deploy NFD on any linux distribution without the need to tailor the binary packages for each.
>
> ---
> Alex
>
> On Aug 31, 2014, at 6:08 PM, Felix Rabe <felix at rabe.io> wrote:
>
>> I've just managed to install NFD on Ubuntu inside Docker, it was straightforward thanks to the instructions on http://named-data.net/doc/NFD/0.2.0/INSTALL.html.
>>
>> Dockerfile:
>> ======
>> FROM ubuntu:14.04
>>
>> RUN apt-get update
>> RUN apt-get install -y software-properties-common
>>
>> RUN add-apt-repository -y ppa:named-data/ppa
>> RUN apt-get update
>> RUN apt-get install -y nfd
>> ======
>>
>> If you want man pages, throw an `apt-get install -y man` in there.
>>
>> Caveat: Have not actually run the software :) will do that on my next opportunity before the meeting.
>>
>> - Felix
>> _______________________________________________
>> Ndn-interest mailing list
>> Ndn-interest at lists.cs.ucla.edu
>> http://www.lists.cs.ucla.edu/mailman/listinfo/ndn-interest

-------------- next part --------------
# Using NFD with Docker

Docker is a command-line frontend to operating system-level virtualization solutions such as Linux containers (LXC). This allows running application processes in isolation without the overhead of a more traditional VM – for example, there is no (operating system) boot process involved. For more information, see https://www.docker.com/ and http://en.wikipedia.org/wiki/Docker_(software).


## Step 1: Install Docker

Go to https://docs.docker.com/installation/ for installation instructions. Docker runs natively on (recent) Linux kernels, and via a VM on Windows and OS X.


## Step 2: Save the Dockerfile

Create a new directory and put the following in a file called `Dockerfile`:

    # This is based on the instructions from:
    # http://named-data.net/doc/NFD/0.2.0/INSTALL.html#install-nfd-using-the-ndn-ppa-repository-on-ubuntu-linux

    FROM ubuntu:14.04

    RUN apt-get update
    RUN apt-get install -y software-properties-common

    RUN add-apt-repository -y ppa:named-data/ppa
    RUN apt-get update
    RUN apt-get install -y nfd

The syntax is documented at http://docs.docker.com/reference/builder/.


## Step 3: Build the image

Open a terminal and change to the new directory created above, and execute the following command to build an image called `named_data/nfd`:

    docker build -t named_data/nfd .

This is similar to a compilation step to transform source code (the Dockerfile) into executable code (the Docker image). If you are new to Docker, the first time you run that command, it will pull the Ubuntu base image, which will take some time. Later rebuilds happen fast, thanks to Docker's snapshotting.


## Step 4: Run a shell from the image

To start a process (create a Docker container), you use the `docker run` command. As you might want to explore the Docker container at first, this shows you the usual way to start a Bash process that leaves no traces: (`--rm` removes the container afterwards)

    docker run --rm -ti named_data/nfd /bin/bash

You find the full documentation of the `docker run` command at https://docs.docker.com/reference/run/, and the full command-line reference at https://docs.docker.com/reference/commandline/cli/.


## Next steps

There is an interactive Docker tutorial at https://www.docker.com/tryit/, and more documentation at https://docs.docker.com/. `docker help [command]` is also helpful.

Docker works best if a container runs only one process at a time, such as NFD. Bash is usually only used for exploration. To trim down the image, consider using Debian (90 MB) or Busybox (2.5 MB) as a base image instead of Ubuntu (225 MB). (There are currently no instructions for these base images, as these distributions are currently not supported / tested by the Named Data project.)

(TODO: Push a trusted build to https://registry.hub.docker.com/ so others can directly pull the pre-built image.)


## Summary of the Docker command line

This section lists the `docker` commands and arguments that are most commonly used.


### Commands

    build            Build an image from a Dockerfile (`docker build -t imageName directory`)
    run              Run a command in a new container (`docker run --rm -ti ubuntu:14.04`)


### `docker run` arguments: general

Arguments marked with `*` can also be defined in the `Dockerfile`.

    -d                            Run in the background (and use `docker ps/logs/stop/kill`)
    -i                            Keep STDIN open (together with `-t`, for Bash)
    --name containerName          Give a container a name (for `--link` and `--volume-from`)
    --rm                          Remove the container after it exits
    -t                            Allocate a pseudo-TTY (together with `-i`, for Bash)


### `docker run` arguments: networking

    --expose port               * Expose a port for use with `--link`
    --link otherContainer:alias   Link to exposed ports of another container (sets env. vars)
    -p hostPort:containerPort     Publish a TCP port to the host


### `docker run` arguments: filesystem

    -v /containerPath           * Make a mount point available without content (for `--volumes-from`)
    -v /hostPath:/containerPath   Mount a host path into a volume (mount point, also for `--volumes-from`)
    --volumes-from name           Mount volumes from another container


More information about the Ndn-interest mailing list