Container Jobs

What is a Container Job?

A container job is a function that allows you to periodically execute a task using a container image. This way, for example, you can run a script/code every 10 minutes. 

 

Content

  • Why Should You use It?
  • Underlying Technology
  • Step-by-Step Guide
  • FAQs
  • References & Additional Resources

 

Why Should You Use It?

Alternatives

There aren't a lot of alternatives you can use instead of container job. Most alternatives would be a completely other tool. But there is at least one alternative.

  • ContainerA container is essentially the same thing, but the main difference is that a container job is one run while a container is constantly running and will keep trying to run. 

 

Use Cases

The scenarios where a container job is useful can vary greatly. From producing a small message to message processing. Below are a few more examples.

  • Data migration: If you want a backup of the data to be made every month, you can do this in a container job.
  • Generating reports: If you want a report to be generated every day at 18:00, this is a task you want to execute periodically, so it’s best to set it up in a container job.
  • Data ingestion: Fetching data from various resources and processing it is something you may want to perform periodically.
  • Starting message queues: You can produce a message to kick off a message queue.

 

Underlying Technology

Cron Notation

Cron notation is a way of writing that is used to schedule tasks for software or to execute software periodically.

The notation consists of six fields in the following order with the range indicated: minute (0-59), hour (0-23), day of the month (1-31), month (1-12 or JAN-DEC), day of the week (0-6 or SUN-SAT), year (1970-2099).

For example, if you want something to run every day at 12 o'clock, you will write it as 0 12 * * *. And if you want something to run every 15 minutes, you will write it as */15 * * * * *.

 

Entrypoint and CMD

Entrypoint The ENTRYPOINT instruction is used to configure the container to run a specific executable when the container starts. It ensures that a particular command always runs, making it suitable for use cases where the command should not be overridden. 

 

CMD The CMD command specifies the instruction that is to be executed when a Docker container starts. It is used to define the default command that will run when the container is launched. 

 

CMD vs Entrpoint As you can see both ENTRYPOINT and CMD are used to specify what command should run when a container starts, but they have different behaviors and use cases. Here's a concise comparison: 

  • Entrypoint: Sets the executable that will run when the container starts. 
    • The command specified in ENTRYPOINT will always run, and it is harder to override at runtime.
  • CMD: Provides default arguments to ENTRYPOINT or acts as the main command if ENTRYPOINT is not set. 
    • The command specified in CMD can be easily overridden at runtime with command-line arguments. 
    • If ENTRYPOINT is set, CMD provides default arguments to the ENTRYPOINT command. 

 

Step-by-Step Guide

Prerequisites

  • Container ImageA Container image saved in a Container Registry (e.g. Docker Hub) 
  • Private registry info (optional)A private registry source URL, username with an access token or password.

 

Setting up a Container Job

1) Go to the tab 'Container Jobs'.

2) Click on 'Add Container Job+'

3) Fill in everything like you would normally do with a container.

4) If you want to use another ENTRYPOINT than the one specified in your Dockerfile, check the box next to the 'Override container's ENTRYPOINT?' and provide the path to your new entrypoint.

5) Fill in extra CMD's if necessary. You can also add a CMD without changing the ENTRYPOINT

6) Choose when you want the image to be run; the default value is every minute (* * * * *). You can enter this directly as a cron expression, or you can select it manually. Under the cron expression, you can see when the next run will occur.

 

7) Specify whether you want the job to be enabled or disabled. It's enabled by default, when disabled nothing will be ran until you activate it again.

 

8) Click on 'Add Container Job'.

9) Now you container is being created. You can see when the next execution is next to the schedule label.

 

FAQs

  • How can I see if my job will fail or not?You can't immediately see if the job will fail; this is only visible when the job is being executed. This is due to the fact that the image is only retrieved when the job is starting. 

 

References & Additional Resources

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.

Articles in this section