Deploying your Dockerized Application with XL Deploy
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
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: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
Deployment rules for our plugin:
- 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:
How we undeployed our 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:
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
- 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