Building a Docker Container for Batch Applications

Jobs in Control-M have a host attribute to specify the application host on which to run a job. To successfully run the job, the application host must also have a Control-M/Agent.

You can specify either a single host or a host group (that is, a logical name for a collection of hosts).

A host group is used for load balancing. When you specify a host group, Control-M directs jobs to the various hosts in the group according to their current load.

Copy
job1 {
   "host": "application_hostgroup"
   "command": "/home/user1/scripts/my_program.py"
   "runAs": "user1"
}

For this tutorial, a container is provided. This container includes a Control-M/Agent. When running the container instance, the Control-M/Agent self-registers and is added to the host group.

When a job is defined to run on the host group, it will wait for at least one registered container in the host group before it starts to run inside the container instance.

Stopping the container unregisters the Control-M/Agent and removes the container from the host group.

Before You Begin

Ensure that you meet the following prerequisites:

  • You have successfully completed API setup, as described in Setting Up the API, and you have a valid API endpoint and API token..

  • You have a Linux account where docker is installed.

  • You have Git installed. If not, obtain it from the Git Downloads page.

  • You have local copies of the tutorial samples from GitHub and a local copy of the source code using the git clone command:

    Copy
    git clone https://github.com/controlm/automation-api-quickstart.git

Step 1: Building the Container Image

Go to the directory where the tutorial sample is located:

Copy
cd automation-api-quickstart/helix-control-m/102-build-docker-containers-for-batch-application/centos7-agent/

Review the docker file to see how to provision a Control-M/Agent within a docker container.

Enter the following commands on the machine to build a docker container image of Control-M. Within these commands, to generate an endpoint, specify a valid Control-M host, API endpoint, and API token.

Copy
$SRC=
AAPI_ENDPOINT=<tenant's API endpoint>
AAPI_TOKEN=<API token>
 
sudo docker build --tag=controlm \
--build-arg AAPI_ENDPOINT=$AAPI_ENDPOINT  \
--build-arg AAPI_TOKEN=$AAPI_TOKEN $SRC

Note that the token that you specify here is an API token, not an Agent token.

Step 2: Running a Container Instance

Type the following commands, in which CTM_HOSTGROUP is a host group name to which to add the container.

The host group name cannot contain spaces.

Copy
CTM_HOSTGROUP=<application_hostgroup>
AGENT_TAG=<Agent_tag>
 
sudo docker run --net host \
  -e CTM_HOSTGROUP=$CTM_HOSTGROUP \
  -e AGENT_TAG=$AGENT_TAG \
  -dt controlm

The agent tag that you specify must have a matching agent token. For information about generating a token, see Generating an Agent Token.

Review the run_register_controlm.sh to see how the Control-M/Agent is registered to the host group.

Step 3: Viewing Self-registered Container Instances in Control-M

This command allows you to see that an agent with the name <docker host> was added to the list of agents. It also shows you the host group that each listed agent belongs to.

Copy
sudo docker run -i -t controlm ctm config server:agents::get IN01

Step 4: Running a Simple Job Flow in the Docker Container

View the JobsRunOnDockerSample.json file to see what the output of the command is inside the container.

Edit the file ../JobsRunOnDockerSample.json and replace "Host": "<HOSTGROUP>"with the host group name created in Step 2.

Run the jobs in the docker container:

Copy
sudo docker run -v $PWD:/src -i -t controlm ctm run /src/JobsRunOnDockerSample.json

This command enables you to inspect how the jobs run inside the container:

Copy
sudo docker run -i -t controlm ctm run status <runid>

Step 5: Decommissioning the Container Instance

To remove and un-register the container Control-M/Agent from the host group and Control-M, type the following command:

Copy
sudo docker exec -i -t <docker id> /home/controlm/decommission_controlm.sh
sudo docker stop <docker id>