CronExpression not working inside docker
CronExpression can be scheduled but never gets executed.
method: ScheduleWithCron(..., ..., chrono.WithLocation("Europe/Berlin")) expression: does not matter, also */1 * * * * not working docker-file to build and run:
# The base go-image
FROM golang:1.18-alpine as build
# Create a directory for the app
RUN mkdir /app
# Copy all files from the current directory to the app directory
COPY ./src /app
# Set working directory
WORKDIR /app
# go build will build an executable file named tics in the current directory
RUN go build -o tics
FROM alpine:latest AS bin
# copy from temporary "build"-image to the current
copy --from=build /app/tics /tics
copy ./tics.yml /tics.yml
EXPOSE 3222
RUN /bin/sh
# Run the tics executable
ENTRYPOINT ./tics
running the same source outside docker as an executable works.
do you have any ideas?
I don’t have any idea about this problem. but thank you for letting me know that. I’m gonna investigate the root cause of the problem.
did you had time to investigate or need more information? Thank you
I could not have enough time for the investigation because of my workload. this week, I hope I have enough time for figuring out the problem.
@peatle-mibt It seems your cron expression you are using is wrong, when I try to schedule a function with the same cron expression, I got an error like saying cron expression must consist of 6 fields. Can you please try to fix your cron expression and try it again? Sorry for late checking the issue. Please also let me know if you have any problem.
@peatle-mibt your cron expression should be */1 * * * * *. I'm closing the issue. :)

It turns out this is not an issue because the cron expression used is wrong. so this issue will be closed.
I'm sorry, but this was a mistake in the description. it is still not working. From my log when starting:
2022-07-25 08:30:14.921 [INFO] starting reminder service with cron expression */1 * * * * *
I don't see any error in the log and i don't see any msg saying that my scheduled method is called. The method called with ScheduleWithFixedDelay is working. As I said, this only happens inside a docker container.
I also tried to schedule a task with the expression you specified inside docker. It worked for me. Could you give me some code snippets for investigation? I just reopened this issue.
strange...my code that I tested is:
Scheduler := chrono.NewDefaultTaskScheduler()
Scheduler.ScheduleWithCron(func(ctx context.Context) {
log.Info("ping cron")
}, "*/1 * * * * *", chrono.WithLocation("Europe/Berlin"))
Scheduler.ScheduleWithFixedDelay(func(ctx context.Context) {
log.Info("ping delay")
}, time.Duration(5000*int(time.Millisecond)))
ping delay gets printed, the other not. in windows and with vscode it works.
The OS for docker Linux 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux
docker version: Docker version 20.10.5+dfsg1, build 55c4c88
Hi @peatle-mibt Can you please confirm that the issue has been resolved with release v1.1.2?
Hello. I can confirm that it works without using a location, but with location it isn't.
Hi, You are using release v1.1.2?
yes I do. I also tried it within ubuntu 22.04 but no luck, sorry.
I found the root cause of the problem, it occurs because timezone data is missing in container and it cannot load location info.
If you add the following line in your Dockerfile,
RUN apk add —no—cache tzdata
It should work as expected.
Can you please try this solution?
thank you!!! that did the trick, so it is an docker/image problem, not with your code. But maybe it would be possible to show some kind of error or warning when location info is not available.
You’re welcome. Right, it was an issue with Docker image.
Actually, when I tried this, schedule function was returning an error saying error: could not load time location .
You can check returned error value after scheduling.
It turns out this is not an issue with chrono. So this issue will be closed
I see. that's little weird about golang, errors can be ignored without explicitly doing so.