Automated installation of Virgo with Docker

Docker logo 011 Automated installation of Virgo with DockerA few weeks ago a friend of mine enthusiastically told me about Docker[1] in a lunch break. Yesterday he supported me in creating my first Dockerfile and it was an amazing experience I must admit.

But let’s start at the beginning.

What is Docker?

Docker is a Linux Container Runtime, that runs Unix processes with strong guarantees of isolation. Under the hood Docker uses LXC[2] (LinuX Containers) which provides operating system-level virtualization and the aufs[3] a stackable unification filesystem. This is to say each container has its own root filesystem, its own system resources like cpu and memory and an isolated network.

How do you install Docker?

The only command you have to run with root privileges is the actual installation of Docker which is more or less issuing one command:

$ sudo apt-get install lxc-docker

How do you run Docker?

After installation you can continue as standard user and run a bash for example in a new Docker container tagged “ubuntu” using the interactive mode.

$ docker run -i -t ubuntu /bin/bash
root@aae20ef84f48:/#

How do you use Docker to build your own Docker based Virgo[4] container?

Finally we are at the Dockerfile again. Here is where the real automation starts. The format of a Dockerfile is human readable and still impressively simple. But assure yourself:

# Our Virgo container is based on an Ubuntu 12.10 
FROM base:ubuntu-12.10
 
RUN apt-get update
 
# What else do we need? Java.
RUN apt-get install -y openjdk-7-jre-headless
 
# We do not want to run Virgo as root so let's add user virgo
RUN useradd -m virgo
 
# install tools for downloading and extracting virgo
RUN apt-get install -y curl
RUN apt-get install -y bsdtar
 
# download and extract Virgo Jetty Server right into the home directory
RUN curl -L 'http://www.eclipse.org/downloads/download.php?file=/virgo/release/VP/3.6.2.RELEASE/virgo-jetty-server-3.6.2.RELEASE.zip&r=1' | bsdtar --strip-components 1 -C /home/virgo -xzf -
 
# change the owner and fix the file permissions
RUN chown -R virgo:virgo /home/virgo
RUN chmod u+x /home/virgo/bin/*.sh
 
# expose Virgo standard port so we can access the admin console from the host
EXPOSE 8080
 
# workaround to be able to resolve localhost from within Java
RUN sed -i "s/^127.0.0.1/127.0.0.1 $(hostname) /" /etc/hosts
 
# start Virgo
CMD su - virgo /home/virgo/bin/startup.sh

This is what you need to easily distribute and run a Virgo container in a reproducible way. Could be the content of a project’s Wiki page “How To setup Virgo”, but it is actually sort of a “Makefile” to build a Docker Virgo container.

So let’s build[5] the Virgo container and tag it “eclipsesource/virgo”. Under the hood Docker creates a commit for every automated step and even caches those steps to be able to continue e.g. without downloading Virgo over and over again while developing and testing as you create your Dockerfile.

$ docker build -t eclipsesource/virgo .
Step 1 : FROM base:ubuntu-12.10
 ---> b750fe79269d
…
Step 4 : RUN apt-get install -y openjdk-7-jre-headless
 ---> Using cache
 ---> 4fae753cdd3e
…
Step 13 : CMD su - virgo /home/virgo/bin/startup.sh
 ---> Running in cf4056c866df
 ---> 911a6243d6f1
Successfully built 911a6243d6f1

We successfully build the container. So let’s start a bunch of them right away:

$ docker run -d -t eclipsesource/virgo
$ docker run -d -t eclipsesource/virgo
$ docker run -d -t eclipsesource/virgo

With the ps command you can easily track your running containers:

$ docker ps
ID                  IMAGE                        … PORTS
3bc350ecb138        eclipsesource/virgo:latest   … 49156->8080
f8f6bee93df3        eclipsesource/virgo:latest   … 49155->8080
a64af829186c        eclipsesource/virgo:latest   … 49154->8080

As you can see there are three unmodified Virgo Jetty Servers up and running in an isolated container and the admin console of each of them can be reached through the ports 49156, 49155 and 49154.

Sidenote:
Docker is still under heavy development and should not yet (at the time of writing July 2013) be used in production. But I will for sure check the repository closely.

[1] Docker – http://www.docker.io/
[2] LXC (LinuX Containers) – http://en.wikipedia.org/wiki/LXC
[3] aufs http://aufs.sourceforge.net/aufs.html
[4] Virgo – http://eclipse.org/virgo/
[5] Build a container from a Dockerfile – http://docs.docker.io/en/latest/commandline/command/build/

4 Responses to “Automated installation of Virgo with Docker”

  1. Moritz Post says:

    Nice post. I never heard of docker but i just wanted to add that the new Ubuntu Touch mobile OS also uses LinuX Container to embed Android on top of Ubuntu. :)

    http://www.androidcentral.com/ubuntu-touch-no-longer-just-another-android-shell

  2. Markus Kohler says:

    Docker seems like a fantastic idea. I wanted to play around with it since weeks, and buidld my own container. Thanks to your post, this should be easier now :-)

    Virtualized development environments are the way to go for cloud developement IMHO. Eclipse support for Docker would be great to have as soon as Docker gets stable.

  3. Andy Rothfusz says:

    I found I needed to add “RUN apt-get update” before the bsdtar installation or else it couldn’t find the bsdtar package.

    – metalivedev

  4. Florian Waibel says:

    Thanks for spotting this. Seem this line got lost while putting the post together. I have updated the Dockerfile.

4 responses so far

Written by . Published in Categories: Editors choice, Planet Eclipse

Author:
Published:
Jul 3rd, 2013