Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

382
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda