Simple scheduling for short-running Docker containers https://blog.iamthefij.com/2018/11/19/introducing-dockron-scheduling/
Go to file
Ian Fijolek 81211d1340
Some checks failed
continuous-integration/drone/push Build is failing
Attach to exec jobs and print their output
Still no logging or means of detecting failed attempts
2024-09-26 11:48:11 -07:00
itest Attach to exec jobs and print their output 2024-09-26 11:48:11 -07:00
.drone.yml Skip docker-compose hook 2021-05-13 14:07:07 -07:00
.gitignore Add integration test 2020-08-19 14:13:28 -07:00
.pre-commit-config.yaml Upgrade pre-commit hooks 2024-09-25 12:05:17 -07:00
docker-compose.yml Add the ability to create execute jobs on long running containers 2020-08-19 14:13:28 -07:00
Dockerfile Add pre-commit and clean up 2020-08-07 15:00:30 -07:00
Dockerfile.multi-stage Upgrade dependencies and go version 2024-09-25 11:58:41 -07:00
go.mod Upgrade dependencies and go version 2024-09-25 11:58:41 -07:00
go.sum Upgrade dependencies and go version 2024-09-25 11:58:41 -07:00
LICENSE Add pre-commit and clean up 2020-08-07 15:00:30 -07:00
main_test.go Attach to exec jobs and print their output 2024-09-26 11:48:11 -07:00
main.go Attach to exec jobs and print their output 2024-09-26 11:48:11 -07:00
Makefile Fix tag version propogation 2020-12-01 19:42:03 -08:00
manifest.tmpl Add multi-arch builds 2019-06-07 16:43:15 -07:00
README.md Add note in readme about docker api version errors 2024-09-25 12:04:06 -07:00

Dockron

Simple scheduling for short-running Docker containers

Usage

Dockron requires access to the Docker, so it may need to be run as root, or, if in a Docker container, need the socket mapped as a volume.

Running Dockron

As simple as:

dockron

It will then run in the foreground, periodically checking Docker for containers with labels containing a cron schedule.

By default, Dockron will periodically poll Docker for new containers or schedule changes every minute. You can specify an interval by using the -watch flag.

Running with Docker

Dockron is also available as a Docker image. The multi-arch repo can be found at IamTheFij/dockron

From either an amd64, arm, or arm64 machine, you can run Dockron using:

docker run -v /var/run/docker.sock:/var/run/docker.sock:ro iamthefij/dockron -watch

Getting a Docker API Version error?

You might see something like the following error when Dockron connects to the Docker API

Error response from daemon: client version 1.47 is too new. Maximum supported API version is 1.45

This is because the API client library is newer than the version of the Docker API on your host. You can tell the Dockron API Client to use a compatible version by specifying DOCKER_API_VERSION=1.45, where the version you specify matches the API version shown when you run docker version. If you are running Dockron in Docker, make sure you add this to your compose environment or otherwise pass it to the container.

Scheduling a container

First, be sure your container is something that is not long running and will actually exit when complete. This is for batch runs and not keeping a service running. Docker should be able to do that on it's own with a restart policy.

Create your container and add a label in the form 'dockron.schedule=* * * * *', where the value is a valid cron expression (See the section Cron Expression Formatting).

Dockron will now start that container peridically on the schedule.

If you have a long running container that you'd like to schedule an exec command inside of, you can do so with labels as well. Add your job in the form dockron.<job>.schedule=* * * * * and dockeron.<job>.command=echo hello. Both labels are required to create an exec job.

Eg.

labels:
    - "dockron.dates.schedule=* * * * *"
    - "dockron.dates.command=date"

Note: Exec jobs will not log their output anywhere. Not to the host container or to Dockron. It's up to you to deal with this for now. There is also currently no way to health check these.

Cron Expression Formatting

For more information on the cron expression parsing, see the docs for robfig/cron.

Caveats

Dockron is quite simple right now. It does not yet:

  • Issue any retries
  • Cancel hanging jobs

I intend to keep it simple as well. It will likely never:

  • Provide any kind of alerting (check out Minitor)
  • Handle job dependencies

Either use a separate tool in conjunction with Dockron, or use a more robust scheduler like Tron, or Chronos.

Building

If you have go on your machine, you can simply use make build or make run to build and test Dockron. If you don't have go but you do have Docker, you can still build docker images using the provide multi-stage Dockerfile! You can kick that off with make docker-staged-build

There is also an example docker-compose.yml that will use the multi-stage build to ensure an easy sample. This can be run with make docker-example.

Tests

There are now some basic tests as well as linting and integration tests. You can run all of these by executing make all.