Ship your Scala code often and easy with Docker

At SpeedLedger we have during the last year been working with gradually containerizing our services using Docker. At the moment we have 20 different services containerized that are running in production. During this period we have learned a lot and made a lot of mistakes. We are using a number of tools and developed some of our own. For example our deployment tool is built in-house and is responsible for starting and configuring our Docker containers in a standardized way to handle logging and service registration for our applications.

At the end of April it’s time for this years edition of the flatMap conference in Oslo. I (Marcus Lönnberg) will be hosting a talk there about how to deploy Scala applications using Docker. Some of the talk will be general about Docker and various tips from my journey with it at SpeedLedger. I will also talk a bit about how one can use sbt-docker, which I recently released version 1.0.0 of, to easily build Docker images using sbt. There will also be a few other tools that we will look into, for example the deployment tool we have developed at SpeedLedger.

Docker meetup startup resumé

The day after creating the Docker Göteborg Meetup group, around 30 members had joined. Now the are 65 Dockers in the group. The interest and buzz about Docker is intense for sure.
We started the group 21th of October this year and we decided to start off with a introduction meeting. It felt right to have a small group of people (20) and focusing on discussions instead of presentations. Here follows a brief summary of the meeting.

Short introduction of all participants

Everybody introduced themselves. The DRY principle was heavily applied since some people worked at the same company =)

Group introduction

Me and Marcus Lönnberg (the group organizers) are working at SpeedLedger and we started using Docker at SpeedLedger half a year ago. We started to use Docker for some of our internal services and single purpose production services. When we were in  the starting blocks of putting Docker in to use on our flagship product we felt the need to discuss Docker topics in a bigger forum. Hence the meetup group. We also have a co-organizer Katya from Docker who offered her help.

Leading presentation and discussion

We started by defining Docker together by writing down properties and characteristics. Most of them were positive but also some negatives were addressed. We moved on and started talking about how we are using Docker at SpeedLedger. We draw our production environment and a lot of question came up. These were some of the questions:
“How are you coping with docker host updates?”
“Where do you keep configuration? Inside or outside container image?”
“How do you communicating between containers?”
“How is the new production environment working out? Problems?”
“How do you deploy new images?”
A lot of good questions and interesting ideas. To summarize, the majority of the participants are not using Docker in production yet. Some are using it for other purposes such as test environments though.

What now?

We talked about practicalities around the next meetup. We will surely try to gather many more participants for the next meetup in order to involve and attract as many people as possible to the group. Seems like the next meetup would gain popularity by doing having more in-depth presentations. Lets see how that turns out!
Right now I am in Amsterdam and looking forward to attend the DockerCon Europe 2014 conference. If you want to see what comes out of it, follow me on Twitter and continue to follow this blog…
Take care folks!
alt text

Docker is live!

Finally we have come to the point where we have started using Docker containers in our production systems. We have already used the lightweight container platform for smaller applications and now we have rolled it out for our flagship product in production as well.

A couple of days ago we had a internal brown-bag-lunch showing off what we have achieved so far. Both teams have been involved in discussing the new infrastructure and now we have rolled it out for 10% of our users. The following days we will monitor the new instance and hopefully ramp up to 100% load.

The primary incentive for containerizing our production environment was to achieve zero-downtime deployments. As we were keen on moving away from the old production environment, creating yet another Tomcat instance was not an option.

By using Docker we have drastically changed our production environment. It now has the following nice characteristics.

Everything is version-controlled

We now have fine grained control and history of how our production environment changes over time.  Also, we know where to look when a question comes up about our production environment; our source code repository. A new employee can easily understand and gain an overview of the production environment setup.

Light-weight environments

Docker containers are really fast to spin up and a container does not consume the same amount of resources as a plain old VM with Guest OS. This enables  us to create small and designated containers with a single purpose, as opposed to our old production environment where all services run on the same machine. “Separation of Concerns” ftw!

Reproducible production environment

Since an image is portable and guaranteed to work the same way whichever host it is running on, we can easily reproduce the production environment. This eliminates a lot of uncertainties that are present when you troubleshoot a production error.

Next steps

Using Docker in production is an important milestone. More importantly, it enables us to proceed with many other improvements.

Continuous Integration build

We are starting to make use of commands we created to automatically build and push Docker images on CI (We are trying out Bamboo).

mvn clean install -PbuildDockerImage,pushDockerImage

Our build runs a lot of integration tests that require an Oracle database. Using Docker, we are able to spin up an Oracle container on start, run our build (including integration tests) and finally stop the database container in three well defined steps in our build cycle.

Deployment tool

We are in the middle of developing a new deployment tool, called “Haddock”. It will help us automate a lot of deployment steps that we currently perform manually. Haddock takes a tag of the image we want to release, communicates with the Docker daemon on the host we want to spin up a new production instance and asks the Service Locator to direct traffic to it. We are in the middle of extracting some logic from our proxy into a service locator like app. The proxy will only direct new traffic to the new instance since we need sticky sessions for our running clients. When all client sessions have expired, we can remove the old instance from production without downtime for users.


We are really excited about our new production environment we can not wait to start utilizing our new infrastructure for a Continuous Deployment scenario. This is just the beginning…


Containers for test environments using Docker

We have started moving all our internal services from our local servers to cloud based. One big part of that job is to move all test environments. We took the opportunity to the revise that infrastructure. Before, our environments were pretty much static. One Tomcat per application and communication between them was set up in the products configuration modules. One ActiveMQ instance with a lot of environment prefixed queue names to communicate between applications. A pretty messy setup actually.

As long as we had a sufficient number of environments we could deploy new versions quite easily. The obvious problem is that the number of environments increase and that it requires manual steps to spin up a new environment.
Another flaw is that the test environment also differs too much from the production environment since multiple test environments run on the same host. And what about the production environment. How is it set up? Well, we have documents describing the packages needed, firewall configuration, applications’ locations and so on but none of these are 100% accurate.

Docker to the rescue

We do not want to have a limitation on the number of test environments we can run. We want our environment configuration (installed packages, scripts, configuration files, environment variables etc) to be versioned in a VCS. Setting up a new environment must go fast!

Marcus Lönnberg recommended Docker after using it quite a while. Docker is a Linux container engine with means to do lightweight virtualization. Images are built and can be used in any Linux environment compatible with Docker. Images are built hierarchical on top of each other which enables image reuse and avoids configuration duplication.

We run a private repository for our Docker images where we can push updated and new images to and pull down images from. All our Docker files and image build scripts are kept in Git, so all changes made to our environments are version controlled in contrast to the mutable production environment we are running today.

We have just started using Docker and completed our first story that enables us to create a new test environment involving four containers.
  • ActiveMQ
  • SpeedLedger accounting system (app container)
  • Login and proxy (app container)
  • Database
These containers constitute one test environment. They are tied together when started by giving them links to each other. That way the containers can use link names to communicate. This is how we start up a new test environment currently.
lis@lis-vm:~$ cat launch-test-environment

NAME_POSTFIX=<code>date +%Y%m%d-%H%M%S</code>
set -e

echo $DB_NAME
docker run -t -d -p 1521 --name $DB_NAME $IMAGE_PREFIX/oracle-xe:sl

echo $JMS_NAME
docker run -t -d --name $JMS_NAME $IMAGE_PREFIX/activemq

echo $APP_NAME
docker run -t -d \
--name $APP_NAME \
--link $DB_NAME:oracle \
--link $JMS_NAME:activemq \

docker run -t -d -p 8080 \
--name $PROXY_NAME \
--link $DB_NAME:oracle \
--link $APP_NAME:accounting \
--link $JMS_NAME:activemq \
We build up our containers in a hierarchy where ubuntu is the base image. App container docker files reside in each app’s repository.

All other images are built up by source in a separate repository. Below is a snapshot of the current source structure of that repository.

Every time Jenkins builds our applications we plan to build a new image identified by application VCS changeset branch and hash. This image is based on a tomcat image and has the newly built war file contained. The image is then pushed to our docker registry and ready to be pulled down when spinning a test environment. We might just do that automatically for every change until we see that the number of concurrent test environments is unreasonable high. The big advantage is of course always having a test environment ready without even pushing a button in Jenkins.

To avoid having too many containers up and running at the same time we will probably have a monitoring application that stops running containers if they have not been used for some period of time.

Using it in production

So far we only use containers for test environments. A nice side effect by running lightweight containers in the cloud is that we could quite easily turn a test environment into a production node given an infrastructure that supports multiple simultaneous production environments with a controller in front registering existing environments. We simply have to switch out the database link for the app containers and direct some amount of traffic to it.

By monitoring our environments we could make sure an environment with high error rate automatically would be stopped and stop traffic to it. A successful new environment (zero errors) would be given more and more traffic until old versions are out of service and a new environment is starting up. Realistically we would hava a couple of different versions up and running as our stories are completed, automatically built by CI and pushed to production. As we are committed to increase our team velocity and decrease cycle time, more and more stories will be completed per time unit. That implies an increasing number of production deploys and probably more concurrent running environments.

I have seen some variants of this architecture in presentations given by Twitter and Netflix. Netflix announced Asgard  as Open Source back in 2012.

This is our plan to solve the problem with having a static type of test environment infrastructure. It would be interesting to hear about your experiences. How do you address the complexity of having n test environments?