0

I am creating a project where an shell script should run every 1 hour. I am using cron pattern in-order to run the script every 15 mins. When I tried this with Ubuntu docker image everything was working neat and clean. But when it comes to alpine image, there are some issues with running crond service. Below is the Dockerfile that I am using.

FROM alpine

RUN apk update

RUN apk add --no-cache tini openrc busybox-initscripts

RUN apk add --no-cache logrotate

COPY . .

Here I am using busybox-initscripts for installing the crond service and openrc for getting the rc-service enabled.

Once I have build the image, I am running this container as interactive with following commandss

>>> docker build . -t alpine-test
*Build success*

>>> docker run -it alpine-test /bin/sh

/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.16.2
PRETTY_NAME="Alpine Linux v3.16"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

Below is the commands that I am running inside the docker container (alpine)

When I tried to see the status of crond service using rc-service command it was showing some warning.

/ # rc-service crond status

 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel

Here I have tried to create the softlevel using touch

/ # touch /run/openrc/softlevel

touch: /run/openrc/softlevel: No such file or directory

But it was not created since the openrc path was not there.

/ # ls -la /run

total 12
drwxr-xr-x    1 root     root          4096 Aug 10 15:35 .
drwxr-xr-x    1 root     root          4096 Aug 11 00:39 ..

So I have manually created that path using mkdir

/ # mkdir /run/openrc

Then it was fixed

/ # touch /run/openrc/softlevel

After that I was able to run the rc-service command

/ # rc-service crond status

 * status: stopped

But when I tried to start the service it was giving me a warning that the crond service was already starting.

/ # rc-service crond start

 * WARNING: crond is already starting

Surprisingly when I check the status it was again saying the crond service is stopped.

/ # rc-service crond status

 * status: stopped

Then I have tried stopping the crond service, restarting the service. unfortunately the status of the service was stopped only.

/ # rc-service crond stop

 * ERROR: crond stopped by something else
/ # rc-service crond start

 * WARNING: crond is already starting
/ # rc-service crond status

 * status: stopped
/ # rc-service crond restart

 * WARNING: crond is already starting
/ # rc-service crond status

 * status: stopped
  • 1
    A Docker container runs a single process; it's not a virtual machine that runs an init system with multiple services. Does [this answer](https://stackoverflow.com/a/47960145) to [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) provide a useful recipe for you? – David Maze Aug 11 '22 at 03:15

0 Answers0