MikaelElkiaer / Beehive

A Docker cron task scheduler for running Docker containers via label definitions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Beehive Build Status

Beehive is a simple cron task scheduler meant to be connected to a Docker host. It was created for running in a Docker container while connected to its host's docker.sock. This way it can watch labels for registered containers and run them as per their cron schedule.

Beehive checks every minute if any containers, with the beehive labels, are supposed to run that minute. This means that the highest frequency tasks can run with is 1 minute.

Image on Docker Hub

https://hub.docker.com/r/mikaelelkiaer/beehive

Starting Beehive

Below is described how to run Beehive using the Docker Hub image.

docker run

docker run -d -v /var/run/docker.sock:/var/run/docker.sock mikaelelkiaer/beehive

docker-compose

version: '3.7'
services:
  beehive:
    image: mikaelelkiaer/beehive
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - TZ=UTC # A valid IANA (TZ database) time zone
      - LOG_LEVEL=INFORMATION # (VERBOSE|DEBUG|INFORMATION|WARNING|ERROR|FATAL)

Registering a task

A task is registered by attaching 2 labels to a container:

  • beehive.enable=true - task will only be run if set to true, any other value will leave it disabled.
  • beehive.cron - defines the task schedule using Cronos' extended cron format.

Additional options

  • beehive.replace-running - defaults to false - skipping already running tasks. If set to true - the already running container will be stopped and replaced by a fresh run.

docker create

  • Use docker create to register a container with a configuration, but without running it:

docker create -l beehive.enable=true -l "beehive.cron=*/2 * * * *" --name hello-world hello-world

  • Remove and re-add to update the task schedule:

docker rm hello-world || docker create -l beehive.enable=true -l "beehive.cron=*/5 * * * *" --name hello-world hello-world

  • Remove and re-add to disable the task:

docker rm hello-world || docker create -l beehive.enable=false -l "beehive.cron=*/5 * * * *" --name hello-world hello-world

docker-compose

version: '3.7'
services:
  hello-world:
    image: hello-world
    labels:
      - "beehive.enable=true"
      - "beehive.cron=*/2 * * * *"
  • Register the tasks via up:

docker-compose up --no-start

  • Update the tasks through changing the docker-compose file and re-running

docker-compose up --no-start

  • Disable all tasks via down:

docker-compose down

About

A Docker cron task scheduler for running Docker containers via label definitions


Languages

Language:C# 98.7%Language:Dockerfile 1.3%