“Current versions of Docker include swarm mode for natively managing a cluster of Docker Engines called a swarm.” Version 9 of the IBM UrbanCode Deploy (UCD) Docker plugin adds new steps to create, manage and deploy to these clusters. This document will describe how to create a UCD application that implements the “Get started with Docker” guide discussed here.
Follow the setup instructions described in Part 1 to initialize the swarm manager and worker hosts. This basically involves installing Docker Engine 1.13 or higher on each host. You will need to install a UCD agent on each of the swarm hosts. The UCD agent processes will need to be run by a user that can execute the Docker command. You will also need to load the Docker plugin into your UCD server via Settings->Automation Plugins->Load Plugin.
Download the example UCD application “DockerSwarmGettingStarted” and import it into your UCD server via Applications->Import Applications. Be sure to click the Import with Snapshots checkbox to import required component version artifacts.
Once the import is complete, open the DockerSwarmGettingStarted application in UCD and create a new environment. Add a Base Resource to the new environment and add the agents for each of the swarm hosts setup above to the Base Resource. Next, add the GettingStarted component to each of the agents. Click the Add Tag icon to add a resource tag named SwarmWorker to each of the GettingStarted components under agents associated with swarm worker nodes.
Click the Add Tag icon to add a resource tag named SwarmManager to the GettingStarted component under the agent associated with swarm manager node. When you are done your new environment should look similar to the following.
Now that we have the application environment setup, we will take a look at the application process named CreateDockerSwarmAndDeployStack which creates/initializes the swarm, adds worker nodes to the swarm, and then deploys the GettingStarted application to the swarm. The steps in this process are shown below.
Step 1 is an Install Component step that will execute the Initialize Swarm process from the GettingStarted component to create/initialize the docker swarm. It will only execute on the agent that has the SwarmManager resource tag. Step 2 is a For Each Tag step from the Utility Steps section of the design pallet. For each component that has the SwarmWorker tag, step 3 is executed. This will execute the Join Swarm component process on each swarm worker host to join them to the docker swarm created in step 1. Finally, step 4 is executed on the swarm manager host to download the docker-compose file which defines the GettingStarted example application and run a ‘docker stack deploy’ command to deploy the application into the swarm.
Now we will take a closer look at the GettingStarted component processes that are invoked by the CreateDockerSwarmAndDeployStack application process. The Initialize Swarm process is displayed below.
The Initialize Swarm step from the Docker plugin will create/initialize a docker swarm manager. It will also create output properties (swarmWorkerToken, swarmManagerToken, swarmManagerAddress) that are used to join worker/manager nodes to the swarm. The next two steps in this process will save those values as application properties so they can be referenced when joining the worker nodes to the swarm.
The Join Swarm process is displayed below.
The Docker plugin step Join Swarm will use the application properties named swarmManagerAdddress and swarmManagerToken to add each worker node to the Docker swarm. The Add Inventory Status step is from the Utility Steps section of the palette. It is used to add an inventory entry for the worker node to the environment to indicate the swarm worker has been created.
Finally, let’s take a look at the Deploy Stack component process which is shown below.
First we’ll use a Download Artifacts step from the Repositories section of the palette to download the docker-compose.yaml file that describes the GettingStarted application. Next we’ll invoke the Docker plugin step named Deploy Stack, specifying the downloaded docker-compose.yaml as input. This will launch the application into the docker swarm.
Now that we have walked through the UrbanCode Deploy application and component processes, let’s launch a deployment into our UCD environment and access our GettingStarted application. Go to the DockerSwarmGettingStarted application, Environments tab, and click on the Request Process button for your environment.
Clear the Only Changed Versions checkbox, select CreateDockerSwarmAndDeployStack from the Process field pull-down. Click Choose Versions and select Latest Available from the Select for All pulldown. Click OK, and Submit.
Once your UCD deployment has completed successfully you can access the GettingStarted application on any of the manager or worker nodes in your swarm. Use a browser to access http://swarm-node:80 where swarm-node is the hostname or IP address of one of your swarm worker nodes or the manager node. You will see output similar to the following.
Each time you access the application the Visits count will increment by one. To see a visual representation of where the different containers of your application are running in your swarm you can access http://swarm-node:8080. You should see something like the following.
I hope this post has given you a taste of what you can do with IBM UrbanCode Deploy and Docker swarm mode. To see more information about what you can do with UrbanCode Deploy and containers checkout our new container landing page and let us know what other topics you’d like to see.