Skip to main content
DevOps Image

This post is from the XebiaLabs blog and has not been updated since the original publish date.

Last Updated Jul 07, 2014 — DevOps Expert

Deploying your Dockerized Application with XL Deploy

DevOps

XL Deploy has proven to be a great deployment tool for applications built on any kind of platform including JBoss, WebSphere, IIS, EC2, etc. We like to think we're forward looking when it comes to the tools we need to support in the future to be able to deploy the next generation of applications.

We've been following the recent development around Docker closely, and we can very much imagine that future applications will be built on top of a Docker container. So in one of our recent Tech Rallies, we took some R&D time to experiment with building a Docker plugin for XL Deploy.

We wanted to support the following use cases:

  • Define a deployment package with a Dockerfile and related resources that contains the application
  • As part of the deployment create a Docker image on a Docker-enabled host and register it in the Docker registry
  • The deployment will start a Docker container with the created image
  • Ability to undeploy the application running in the Docker container
Supporting just these use cases is a good starting point for an XL Deploy-Docker integration. This will allow you to take your Docker application from test to production, let XL Deploy do all the work, and manage the lifecycle of your application.

How we set it up:

We took a very simple application as our starting point to test our own Docker plugin. Suppose we want to deploy a very simple static web application. It all starts with a Dockerfile:
Docker file
This Dockerfile defines a container running a Nginx server that serves a static html file. In our deployment package for XL Deploy we placed both the Dockerfile, and the index.html file the application depends on. How did we create a deployment package for XL Deploy? First, we defined two new types:
  • a docker.Build deployable that allows you to specify the image name and a set of files that the image depends on. In our case the Dockerfile and the index.html.
  • a docker.Run deployable that allows you to specify the image name to run and the command to run in the container
Next, we answered a different question: "What kind of infrastructure do we need to run our application?" Since Docker only runs on Linux, we used a Vagrant setup running CoreOS. CoreOS is an interesting project that brings you a minimal Linux distribution that provides just enough to run Docker containers. In order to model this in XL Deploy, we defined a docker.Registry type that extends generic.Container so it can be created on an overthere.SshHost.  We also then created deployeds for our docker.Build and docker.Run deployables that map to our docker.Registry. By doing this, we could now create a deployment package "DockerApp" containing our files, and an Environment "CoreOs" that has an overthere.SshHost to connect to our remote CoreOS instance with a docker.Registry. Now, if we map the DockerApp to the CoreOS environment, XL Deploy creates the following mappings:
mapping application
Since we have not defined any behaviour for our types yet, performing the deployment now would not create any steps in the deployment plan. In order to define the behaviour we need for our deployment, we will use a new way that we have been developing called "deployment rules".

Deployment rules for our plugin:

Rules are a declarative way of defining behaviour that makes defining actions much easier. The new XL Deploy rule system is still under development, so consider this a sneak preview!  It will be released in one of our upcoming releases. In this case, we define three rules. All rules will contribute a step that executes a command on a remote host. We use the "run-command" step to do this. To get an impression of the rules we created look at next screenshot:plugin development with rules
  • To create the image on deployment, we create a rule that runs a "docker build" command on the Docker host on CREATE of a docker.Image.
  • To begin deploying the container, we create a rule that runs a "docker run" command on the Docker host on CREATE of a docker.RunningContainer
    • Notice that when a Docker container is started, we need to remember the container ID to be able to refer to it later. Store the ID of the deployed which can be read from the output of the run command.
  • For undeployment, we create a rule that executes a "docker stop" command on the Docker host on DESTROY of a docker.RunningContainer.
    • We used the stored container ID to stop the right container.
    • Notice that we do not delete the Docker image. There is no particular reason for that, it could be a good extension.

How we ran a deploy:

Now we have all the ingredients to deploy our Docker application. Let's try to deploy the application, and target the application to the CoreOS environment. If we start the deployment, the deployment plan will contain two steps:
  1. Build image
  2. Run container
creating docker imagestarting container
The step log shows that the commands have run successfully and what the output of the commands is. Lets see if the application is now running by running "docker ps" on the CoreOS host, and see if the application is accessible in the browser:
container running application running
Looks good! our application has been successfully deployed.

How we undeployed our application:

undeploy application
In the step log we can see that the container has been stopped. This concludes the deployment and undeployment of the application.

A bonus feature:

Another nice feature of XL Deploy is control tasks. We defined a control task that can retrieve the log files from a running Docker container. The running Docker container used in this example is a running ping command. Executing the control task gives us back the output of the ping command in the running Docker container. We can use control tasks to provide nice tools for dealing with containers. This is a screenshot of the control task in action:ping application

In summary:

The small Docker plugin we built in a couple of hours proves that it is easy to manage simple Docker-based deployments from XL Deploy. The experiment highlighted the following benefits of deploying Docker applications with XL Deploy:
  • Including Docker-based applications in your deployment package
  • Orchestrating your Docker deployments from XL Deploy
    • Running Docker commands through SSH on remote hosts running Docker
  • Letting XL Deploy manage the state of your Docker containers
  • Allowing XL Deploy to perform the lifecycle management of your Docker applications
    • Deploy, Update, Undeploy
  • Creating control tasks to interact with Docker containers and retrieve useful information
We can also think of the following improvements:
  • Building your Docker file dynamically:
    • By using placeholders and building your container with environment-specific values
    • Or letting XL Deploy generate your entire Dockerfile based on your configuration
  • Letting XL Deploy update your application by applying a new Docker layer
  • Adding more control tasks so XL Deploy can serve as a control panel for Docker
These are all features that could be part of a more fully-featured Docker plugin for XL Deploy in future. Watch this space!

More from the Blog

View more
Sep 13, 2021

The Expedited Journey of Digital Transformation

DevOps
Alan Brown, Digital Transformation Advisor at Digital.ai conducts a se ...
Read More
Aug 23, 2021

Is Data Analytics Missing From Your Digital Transformation?

DevOps
Nearly every major enterprise is already in the process of digital tra ...
Read More
Aug 19, 2021

Creative Ways to Automate Developer Workflows

DevOps
When an organization begins an Agile or DevOps journey, the process ca ...
Read More
Aug 12, 2021

How Automation Enhances Efficiency and Delivery Speed In a DevOps Environment

DevOps
When organizations make the decision to move to a DevOps environment, ...
Read More
Contact Us