-1

I need to schedule some cron jobs in docker/kubernetes environment, which will make some external service calls using curl commands. I was trying to use plain alpine:3.6 image but it doesn't have curl.

Any suggestion what base image will be good for this purpose? Also, it will be helpful if there are some examples.

gears
  • 690
  • 3
  • 6
Baharul
  • 145
  • 2
  • 16
  • There is a list of images here: https://hub.docker.com/r/curlimages/curl – julian Dec 06 '19 at 15:03
  • 1
    Does this answer your question? [How to run a cron job inside a docker container?](https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container) – BinaryMonster Dec 06 '19 at 18:12
  • You can also run a [Kubernetes CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) without specifically running cron in a container. – David Maze Dec 06 '19 at 19:02

2 Answers2

1

Prepare your own docker image which will includes packages you need or just use something like this https://github.com/aylei/kubectl-debug

k0chan
  • 681
  • 1
  • 6
  • 14
1

I am able to run curl as cronjob job using alpine image as

FROM alpine:3.6

RUN apk --no-cache add curl bash
RUN apk add --no-cache tzdata

ENV TZ=Asia/Kolkata
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ /etc/timezone

RUN mkdir -p /var/log/cron \
    && touch /var/log/cron/cron.log \
    && mkdir -m 0644 -p /etc/cron.d

ADD curlurl /etc/crontabs/root
CMD bash -c "crond -L /var/log/cron/cron.log && tail -F /var/log/cron/cron.log"

#ENTRYPOINT /bin/bash

Where curlurl is having simple curl command as cron job

* * * * * /usr/bin/curl http://dummy.restapiexample.com/api/v1/employees >> /var/log/cron/cron.log
# Leave one blank line below or cron will fail

This is working fine . But now I have tried to make alpine base image with push in private repo to avoid downloading every time. But it stopped working. How can i debug why cron job is not running anymore. Below is the way I have used.

BaseImage

FROM alpine:3.6

RUN apk --no-cache add curl bash
RUN apk add --no-cache tzdata

ENTRYPOINT /bin/bash

Docker for curl

FROM my/alpine:3.6

ENV TZ=Asia/Kolkata
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ /etc/timezone

RUN mkdir -p /var/log/cron \
    && touch /var/log/cron/cron.log \
    && mkdir -m 0644 -p /etc/cron.d

ADD curlurl /etc/crontabs/root
CMD bash -c "crond -L /var/log/cron/cron.log && tail -F /var/log/cron/cron.log"

After making it like this I am not able to get any cron output . Any suggestion on how can I debug it.

Baharul
  • 145
  • 2
  • 16