Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
Running cron in a docker container on a windows host

I am having some problems trying to make a container that runs a cronjob. I can see cron running using top in the container but it doesn't write to the log file as the below example attempts to. The file stays empty.

I have read answers to the same question here:

  • How to run a cron job inside a docker container?
  • Output of `tail -f` at the end of a docker CMD is not showing

But I could not make any of the suggestions work. For example I used the dockerfile from here: https://github.com/Ekito/docker-cron/

FROM ubuntu:latest
MAINTAINER docker@ekito.fr

# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

#Install Cron
RUN apt-get update
RUN apt-get -y install cron


# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

crontab:

* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job

It didn't work on my machine (windows 10). Apparently there seems to be a windows specific issue also reported by someone else: https://github.com/Ekito/docker-cron/issues/3

To test if it was just me doing something wrong I tried to do the same in a virtual machine running ubuntu (so an ubuntu host instead of my windows host) and that worked as expected. The log file is extended as expected.

So what can I do to try to make this work?

I tried writing to a mounted (bind) folder and making a volume to write to. Neither worked.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

rferalli's answer on the github issue did the trick for me:

"Had the same issue. Fixed it by changing line ending of the crontab file from CRLF to LF. Hope this helps!"

over 4 years ago · Santiago Trujillo Report

0

I have this problem too. My workaround is to use Task Scheduler to run a .bat file that start a container instead

Using Task Scheduler: https://active-directory-wp.com/docs/Usage/How_to_add_a_cron_job_on_Windows.html


hello.bat

docker run hello-world

TaskScheduler Action

cmd /c hello.bat >> hello.log 2>&1

Hope this help :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!