Using Docker to Run Boot From Anywhere
If you've been on the Internet sometime in the last 2 years, you may have noticed that Docker is becoming extremely popular. If you've ever tried Docker*, then you probably know that it's for good reason. Docker is great. The core concept is really pretty simple: Docker uses Linux Containers (LXC) to allow you to run and deploy applications in a controlled environment. You can start from one of the 13,000+ available base images, install packages or otherwise set things up however you'd like in order to run your application, save your configuration as a Docker image, and then spin it up anytime you want, on any machine, anywhere.
This approach has many benefits:
Docker containers are portable. Once you've got your application working within a Docker container, you can run that container on practically any machine, including Windows and OS X environments. You can even run your Dockerized apps on the Amazon EC2, Rackspace, and Google Cloud platforms.
Docker separates applications from infrastructure. Defining your apps in terms of Docker base images means their environments are predictable, making them easier to manage and reason about.
Running your applications in containers is good because it keeps them isolated. Isolating them is good.
Not having to repeatedly set up your application's environment is awesome. Having to do things repeatedly is bad.
Here at Adzerk, we use Docker to deploy services, written in Clojure, to Amazon EC2 / Elastic Beanstalk. Our workflow for developing these services also includes Boot, a fantastic build platform that lets you write tasks related to developing and deploying your Clojure applications. In fact, we have a
boot-beanstalk task that automates the process of Dockerizing apps and deploying them to Elastic Beanstalk.
It's practically as easy as writing a Dockerfile and running a couple of Boot tasks from the command line.
Because the Dockerfile is a part of each application's project repository, the application's environment sort of becomes a part of the project itself! That's pretty cool.
Our workflow of creating Dockerized services set up to run via Boot tasks is starting to become common enough that we've just pushed an official™ boot-clj Docker image to Docker Hub! The great thing about this is that it allows anybody to use Boot in an isolated environment so long as he/she has Docker installed in their system, without having to do any installation or configuration of Java or Boot.
If you have Docker installed, go ahead and give it a try:
docker run -i adzerk/boot-clj repl
This will start up a Clojure REPL in an isolated Linux environment (built on top of the Debian Wheezy Docker base image) with Oracle Java 8 and the latest release of Boot pre-installed.
The next time you want to create a web application in Clojure, you might consider making it a Docker container -- you can now have a Docker container with a functional Debian environment and the latest version of Boot at your disposal just by putting
FROM adzerk/boot-clj at the top of your Dockerfile!
And as another pro tip, here's a tool for Docker logging that's helpful because one concern with Docker is that the containers are stateless and logs can get lost easily.
* And if you haven't, you might consider giving it a whirl - it's fun!