Building a Docker Container for Batch Applications

This tutorial demonstrates how to build a Docker container for batch applications. 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 a host group (that is, a logical name for a collection of hosts).

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.

A host group is used for load balancing. When you specify a host group in the host property of a job (as in the following example), Control-M/Server directs jobs to the various hosts in the group according to their current load. To successfully run the job, all application hosts must also have a Control-M/Agent.

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

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:

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

Begin

  1. Access the tutorial sample with the following command:

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

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

  3. Build a docker container image of Control-M using the following commands.

    CopyCopied to clipboard
    $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

    Within these commands, to generate an endpoint, specify a valid API endpoint, and API token.

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

  4. Run the container instance by typing the following commands:

    CopyCopied to clipboard
    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

    where:

    • CTM_HOSTGROUP is a host group name. The container adds itself to this host group. The name must be without spaces.

    • AGENT_TAG is the Agent tag, and it must have a matching Agent token. For information about generating a token, see Generating an Agent Token.

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

  6. Verify that an Agent with the name <docker host> was added to the list of Agents in the self-registered container instances by running the following command:

    CopyCopied to clipboard
    sudo docker run -i -t controlm ctm config server:agents::get IN01

    The response also shows you the host group that each listed Agent belongs to.

  7. Run a simple job flow in the Docker container by doing the following:

    1. Open the JobsRunOnDockerSample.json file and review the command output inside the container.

    2. Replace <HOSTGROUP> in the JobsRunOnDockerSample.json file with the name of the host group that you created earlier.

    3. Run the jobs in the docker container using the following command:

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

    4. Inspect how the jobs run inside the container using the following command:

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

  8. Decommission the container instance by running the following commands, which remove and un-register the container Control-M/Agent from the host group and Control-M:

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

    sudo docker stop <docker id>