Automated installation of Virgo with Docker

Automated installation of Virgo with Docker

Docker LogoA 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

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 '' | 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

# workaround to be able to resolve localhost from within Java
RUN sed -i "s/^ $(hostname) /" /etc/hosts

# start Virgo
CMD su - virgo /home/virgo/bin/

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/
 ---> 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.

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 –
[2] LXC (LinuX Containers) –
[3] aufs
[4] Virgo –
[5] Build a container from a Dockerfile –

  • Posted at 11:24 am, July 4, 2013

    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. 🙂

  • Markus Kohler
    Posted at 9:43 am, July 5, 2013

    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.

  • Andy Rothfusz
    Posted at 2:28 am, July 23, 2013

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

    — metalivedev