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/Server 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 already set up your environment, as described in Setting Up the Prerequisites, and you have a valid Control-M endpoint, username, and password.

  • You have a Linux account where docker is installed.

Step 1: Building the Container Image

Go to the directory where the tutorial sample is located:

Copy
cd automation-api-quickstart/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, username, and password.

Copy
SRC_DIR=.
CONTROLM_HOST=<controlmHost>
CTM_USER=<ControlmUser>
CTM_PASSWORD=<ControlmPassword>
sudo docker build --tag=controlm \
--build-arg CTMHOST=$CONTROLM_HOST \
--build-arg USER=$CTM_USER \
--build-arg PASSWORD=$CTM_PASSWORD $SRC_DIR

Step 2: Running a Container Instance

Type the following commands where:

  • CTM_SERVER - Control-M/Server name. You can use Config Service to find the accurate name.

  • CTM_HOSTGROUP - A host group name. The container adds itself to this host group. The name should be without spaces.

  • CTM_AGENT_PORT - Control-M/Agent port number. This port should be free on the docker host.

Copy
CTM_SERVER=<control-m server>
CTM_HOSTGROUP=<application_hostgroup>
CTM_AGENT_PORT=<port number>
sudo docker run --net host \
   -e CTM_SERVER=$CTM_SERVER \
   -e CTM_HOSTGROUP=$CTM_HOSTGROUP \
   -e CTM_AGENT_PORT=$CTM_AGENT_PORT -dt controlm

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>:AGENT_PORT was added to the list of agents of the Control-M/Server.

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

This command allows you to see that an agent with the name <docker host>:AGENT_PORT was added to the host group.

Copy
sudo docker run -i -t controlm ctm config server:hostgroup:agents::get $CTM_SERVER $CTM_HOSTGROUP

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>