Skip to content

Building rDSN Docker image

Guoxi Li edited this page Jan 25, 2016 · 4 revisions

Building Docker Image with rDSN installed on it

(All steps have been tested successfully on Ubuntu 14.04)

step 1 install Docker engine

Since Docker engine we need is not in Ubuntu official repos, you can run following scripts as root user to install Docker engine and start Docker daemon:

#!/bin/bash
set -e 

apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo "# Ubuntu Trusty" > /etc/apt/sources.list.d/docker.list
echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list

apt-get update

apt-get purge lxc-docker*

apt-get install docker-engine

echo "DOCKER_OPTS=\"-g /mnt/ssd/docker -l warn\"" >> /etc/default/docker

service docker restart

ps aux | grep docker

DOCKER_OPTS we apply in the scripts are:

  • -g : apply path to use as the root of the Docker runtime. Default is /var/lib/docker. This path will consume a lot of disk space. If your disk where /var/lib/docker is located is not large, you can change it by applying this options
  • -l : set the logging level. Default is info. Docker log in Ubuntu using upstart is at /var/log/upstart/docker.log. If log is too verbose, the Docker log file will so consume a lot of space. We can change it to warn lest disk run out of space.

step 2 building a Docker with rDSN installed on it

Docker using Dockerfile to tell you how a Docker image is built. We can build our own Docker image with just a customized Dockerfile.

FROM ubuntu:14.04

RUN apt-get update && apt-get install -y --no-install-recommends \
		build-essential \
		cmake \
		git \
		php5-cli \
		libaio-dev \
		libboost-all-dev \
		ca-certificates \
        grep \
        python2.7 \
        python-pip \
        gdb        \
        p7zip-full \
	&& rm -rf /var/lib/apt/lists/*
RUN useradd -d /home/rdsn -s /bin/bash rdsn \
    && mkdir /home/rdsn 
COPY script/bash_profile /home/rdsn/.bash_profile
COPY script/bashrc /home/rdsn/.bashrc
RUN chown -R rdsn:rdsn /home/rdsn

ADD rdsn-release.tar.gz /home/rdsn/
ADD MonitorPack.tar.gz /home/rdsn/
WORKDIR /home/rdsn
RUN python setup.py install \
    && pip install -r apps/rDSN.monitor/requirement.txt

ENV HOME /home/rdsn

Dockerfile is like a script showing how to building a Docker Image. As Docker image is a layered filesystem, it can be built upon some famous image like Ubuntu. In our case, we use Ubuntu:14.04 which is a Docker Image you can find on Docker Hub.

In the Dockerfile, we simply add rdsn-release.tar.gz and other necessary binary files that built before to the Docker Image.

  • rdsn-release.tar.gz is the contents of ${TOPDIR}/install where rDSN is installed and there are three directories: include, bin and lib
  • MonitorPack.tar.gz is the contents of GitHub Repo of rDSN.Python

In the script, we just follow the build commands from installation tutorial. For the record, we install /home/rdsn in the Docker image.

After a brief introduction of involved scripts, we just go to source code root directory and run command below:

deploy/docker/build-image.sh

If you don't want put sudo before a command whenever you use a docker command. Just add your username to the group docker.

Building counter Docker Image and running it.

step 1 Building a single Node Counter Service

Please just follow previous tutorial to build a binary of counter.

~/projects/rdsn/tutorial/counter$ mkdir build
~/projects/rdsn/tutorial/counter$ cd build
~/projects/rdsn/tutorial/counter/build$ cmake ..
~/projects/rdsn/tutorial/counter/build$ make -j

To build a Docker image of counter. Just run:

~/projects/rdsn/tutorial/counter/build$ make docker
[100%] Built target counter
Sending build context to Docker daemon 1.178 MB
Step 1 : FROM rdsn-dev
 ---> e66e5fd24995
Step 2 : COPY counter /home/rdsn/
 ---> Using cache
 ---> 8d76086f7357
Step 3 : COPY config.ini /home/rdsn/
 ---> Using cache
 ---> 8c6722a122fc
Step 4 : ENV LD_LIBRARY_PATH /home/rdsn/lib
 ---> Using cache
 ---> 9cd22107ba00
Step 5 : CMD /home/rdsn/counter /home/rdsn/config.ini
 ---> Using cache
 ---> d76283eae1c4
Successfully built d76283eae1c4
[100%] Built target docker
~/projects/rdsn/tutorial/counter/build$

Then, we got our own Docker image named counter-image with counter in it. We can see it with command:

~/projects/rdsn/tutorial/counter/build$ docker images
REPOSITORY                             TAG                  IMAGE ID            CREATED             VIRTUAL SIZE
counter-image                          latest               d76283eae1c4        About an hour ago   1.029 GB
~/projects/rdsn/tutorial/counter/build$

Let's run our Docker image

ID=$(docker run --name counter-service --rm -d counter-image)

Then, we start a Docker Container named counter-service running as daemon. If you want to see the output of it, just run:

docker attach $ID

So, you can see the output in the terminal.