0

I want to schedule a job in a docker container. First of all after looking around i could stablish the container time zone correctly. When i use the command 'date' inside the terminal, it shows the hour of my city and country, but the cronjob works with the time zone that was especified by default in the container. I readed that it's necesary to tell cron, that the time zone has changed. I tried and environment variable TZ_CRON but it didnt work.I also restarted the cron service inside the container but it continued working in the same way.

I base my code in this repo https://github.com/senorihl/docker-compose-cronjob Then i sync the timezone with the command:

environment:
      - TZ=America/Bogota
    command: >
      sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && 
      echo $TZ > /etc/timezone"
    entrypoint: sh /app/crontab.sh

Can you please help me with this?

Leo V
  • 1
  • 1
  • 3
  • [The command and entrypoint get combined together](https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact) so the container's main command is `sh /app/crontab.sh sh -c ...`. Is that what you intend? – David Maze Sep 25 '20 at 17:30
  • Thank you @DavidMaze, now i understand the conflict between command and entrypoint. But it didnt fix the problem. The problem is: The container's cron application works with de default timezone of the container (UTC). Not with the one i set (America/Bogota). – Leo V Sep 28 '20 at 21:22

1 Answers1

0

The way this issue was solved:

I added this volume:

volumes: -/etc/localtime:/etc/localtime:ro

Version of compose: 3

Related post: Using docker-compose to set containers timezones

Leo V
  • 1
  • 1
  • 3