April 18, 201511 yr Hi, I just created a docker for duckdns (dynamic dns) that runs a script that saves the curl output to a log file with a time stamp. Link here: https://registry.hub.docker.com/u/aptalca/docker-duckdns/ and here https://github.com/aptalca/docker-duckdns and template repo here: https://github.com/aptalca/docker-templates When the script is run from cron, the "date" command used outputs UTC time instead of local time. But when I exec into the docker via (docker exec -it Duckdns bash) and run the script manually, it outputs the correct EDT time. Any ideas how I can fix it so it would work for anyone installing this (not hardcoding the US New York timezone)? Thanks
April 19, 201511 yr Author Finally figured this out. Unraid automatically passes the host timezone as an environment argument in the docker run command: docker run . . . -e TZ="mylocaltimezone" . . . This sets the timezone for the user space, but not the system. Meaning, (at least in debian based systems) /etc/timezone and /etc/localtime are still set to UTC. For any script that is run in the user space, the environment setting, the correct timezone is used. However, any script launched by cron uses the system setting, UTC. So for cron scripts to use the local timezone, one must first set the system timezone upon container start. in my dockerfile, I called for a "firstrun.sh", which includes the following three lines that retrieves the local timezone from the environment set by unraid, and sets the system timezone: echo $TZ > /etc/timezone export DEBCONF_NONINTERACTIVE_SEEN=true DEBIAN_FRONTEND=noninteractive dpkg-reconfigure tzdata I hope it helps others
Archived
This topic is now archived and is closed to further replies.