Host a Docker container in Azure and have it active during a specific period of the day?

5/30/2021

I would like to have a docker container active only during certain time's in the day so that a Test Automation can run? Is it possible?

-- Shaun Whyte
automated-tests
azure
containers
docker
kubernetes

2 Answers

5/30/2021

You haven't given much information beside running and stopping a container. One of the simplest way is to use the Docker CLI to run an instance of your container in Azure Container Instances. You create and use a context for Azure and then, using docker run will create an ACI and run your container in Azure.

docker login azure
docker context create aci myacicontext
docker context use myacicontext
docker run -p 80:80 [yourImage]
docker rm [instanceName]

Ref: https://www.docker.com/blog/running-a-container-in-aci-with-docker-desktop-edge/ https://docs.microsoft.com/en-us/azure/container-instances/quickstart-docker-cli

-- CSharpRocks
Source: StackOverflow

5/31/2021

Yes it is possible. Cronjobs is designed to run a job periodically on a given schedule, written in Cron format. A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate.

To run your automation tests

  • You should create a Cronjob definition
  • Set the cron timer
  • Call your CMD

Here is a sample Hello Wordl example:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
-- efdestegul
Source: StackOverflow