Docker Support

Roboconf has a target implementation for Docker.
From the Roboconf perspective, Docker is seen as a kind of IaaS. Roboconf may create and manage docker containers, that run Roboconf agents (just like VMs) and can be used as deployment targets.

To install it, open the DM’s interactive mode and type in…

# Here in version 0.3
bundle:install mvn:net.roboconf/roboconf-target-docker/0.3
bundle:start <bundle-id>

Sample target.properties.
Just copy / paste and edit.

# Configuration file for Docker
target.id = docker

docker.endpoint = http://localhost:4243
docker.image = 0f3087570887
docker.user = guest
docker.password = guest

Here is a complete description of the parameters for Docker.

Property Description Default Mandatory
target.id Determines the target handler to use. none, must be “docker” yes
docker.endpoint The end-point URL of Docker (requires Docker to be setup to use a TCP port). none yes
docker.image The ID or tag (name) of the docker image used as a template for the VM (as shown by “docker images”, for example). If the image is not found, Roboconf will try to generate one, using “<docker.image>:<docker.image>” as its tag: if so, the “docker.agent.package” property is required so that Roboconf knows where to find the roboconf agent to install on the generated image. “generated.by.roboconf” no
docker.user The name of the user to connect. none no
docker.password The password of the user to connect. none no
docker.email The email of the user to connect. none no
docker.version The Docker version (for API compatibility). none no
docker.agent.package If you want this extension to generate a Docker image for you, this parameter points to the ZIP or TAR.GZ file of a Roboconf agent distribution. none no
docker.agent.jre-packages If you want this extension to generate a Docker image for you, this parameter indicates the JRE to install (as a system package), as well as other optional packages, separated by spaces. The package name(s) must be understandable by the apt package manager (Debian-based Linux distributions). openjdk-7-jre-headless no

At least one of docker.image or docker.agent.package must be specified.

Docker Configuration

Here, we assume Docker is already installed on your system (e.g. by using “apt-get install lxc-docker” on Ubuntu, or see docker.com for other platforms). Note that Docker runs mainly on Linux 64-bit systems, although some ports may be available for other platforms.

It is recommended to use docker version 1.5.x or later.

When docker is installed, make sure to obtain a Docker Linux image (e.g. Ubuntu), so you can use it later as a base image for Roboconf agent images. For example, run the following command:

docker pull ubuntu

Configure the TCP port for Docker Containers

Roboconf needs Docker to be available on a TCP port.
To enable it, edit /etc/default/docker, and define DOCKER_OPTS there.

# Make Docker listen on TCP port 4243 (along with local Unix socket)
DOCKER_OPTS="-H=tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"

Then, simply restart docker.

sudo stop docker
sudo start docker

Prepare your own Docker image (NOT necessary if the image is generated by Roboconf)

Start a Docker container using a docker system image (eg. Ubuntu):

docker run -v /tmp:/roboconf -t -i ubuntu /bin/bash

Note: the container started above shares the local /tmp as /roboconf under Docker (using the -v option).
This can be useful to share files between the local file system and the Docker container (e.g. to install the Roboconf agent).

Let’s assume you have copied the Roboconf agent in the shared /roboconf directory (here, the local /tmp).
In the Docker container, execute the following commands.

apt-get update
apt-get install openjdk-7-jre-headless
cd /usr/local
tar xvzf /roboconf/roboconf-karaf-dist-agent.tar.gz
ln -s roboconf-karaf-dist-agent/ roboconf-agent

Now, you have to add a start.sh executable script in the /usr/local/roboconf-agent directory.
Set the following content (the script is mainly used to complete the agent setup at startup time).

#!/bin/bash
# Startup script for docker agent
cd /usr/local/roboconf-agent
echo "# Roboconf agent configuration - DO NOT EDIT: Generated by roboconf" >  etc/net.roboconf.agent.configuration.cfg

for p in "$@"
do
	echo $p >> etc/net.roboconf.agent.configuration.cfg
done

cd bin
./karaf

The container is now ready to become a Docker image.
Outside docker, keep track of its ID, that will be useful to build the image.

Now, your image is created.
Retrieve its image ID using docker images, and use it as docker.image in the Roboconf configuration (target.properties).

Some Docker Tips

Here is a reminder of some Docker commands.

To list docker images:
docker images

To remove a docker image:
docker rmi <image-ID>

To run interactively a docker image (thus launching a container):
docker run -i -v /tmp:/roboconf -t <image-ID> /bin/bash

Note: the -v option is used there to share the local “/tmp” as “/roboconf” in the container, which is useful to exchange files.

To list running docker containers:
docker ps (or, to list them all, “docker ps -a”)

to attach a shell script to a running container:
docker exec -ti <container-ID> /bin/bash

To remove a docker container:
docker rm <container-ID>

To remove all exited containers:
docker ps -a | grep Exit | cut -d ‘ ‘ -f 1 | xargs docker rm

Note to install latest Docker (Ubuntu)

As of March 3, 2015 (docker 1.5.x)…

wget -qO- https://get.docker.io/gpg | sudo apt-key add -
sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker