Automated installation of Virgo with Docker

July 3, 2013 | 4 min Read

https://eclipsesource.comimages/Docker-logo-011.png does not exist A 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 'https://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 - https://www.docker.io/ [2] LXC (LinuX Containers) - https://en.wikipedia.org/wiki/LXC [3] aufs https://aufs.sourceforge.net/aufs.html [4] Virgo - https://eclipse.org/virgo/ [5] Build a container from a Dockerfile - https://docs.docker.io/en/latest/commandline/command/build/