docker-volume-backup icon indicating copy to clipboard operation
docker-volume-backup copied to clipboard

TZ env var doesn't work due to tzdata package missing

Open michael-robbins opened this issue 3 years ago • 5 comments

Currently setting TZ="Australia/Melbourne" has no effect on the containers timezone due to the tzdata package missing.

Before:

root@grafana-backup:~# TZ="Australia/Melbourne" date
Sun Feb  6 03:14:14 Australia 2022
root@grafana-backup:~# TZ="UTC" date
Sun Feb  6 03:14:23 UTC 2022

After tzdata install:

root@grafana-backup:~# TZ="Australia/Melbourne" date
Sun Feb  6 14:15:11 AEDT 2022
root@grafana-backup:~# TZ="UTC" date
Sun Feb  6 03:15:16 UTC 2022

Could we please add this to the container image/setup so we don't have to specify the cron expression as UTC?

michael-robbins avatar Feb 06 '22 03:02 michael-robbins

Could you try mounting this instead?

-v /etc/timezone:/etc/timezone:ro
-v /etc/localtime:/etc/localtime:ro

varhub avatar Feb 06 '22 08:02 varhub

Mounting in both the above still results in the same 'time' reported as both TZ's above.

michael-robbins avatar Feb 06 '22 10:02 michael-robbins

Thats wreid. Could you replicate bellow commands and paste your output?

$ cat /etc/timezone
Europe/Madrid
$ docker run --rm bash date
Sun Feb  6 11:04:35 UTC 2022
$ docker run --rm -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro bash date
Sun Feb  6 12:04:40 CET 2022

[EDIT] Also output of cat /etc/os-release if available of your container

varhub avatar Feb 06 '22 11:02 varhub

I'm using the provided docker-volume-backup container with the Dockerfile in the root of the repo.

root@emojirades-backup:~# ls -l /etc/timezone
-rw-r--r-- 1 root root 8 Nov  6 02:39 /etc/timezone
root@emojirades-backup:~# ls -l /etc/localtime
-rw-r--r-- 1 root root 118 Oct 25 23:58 /etc/localtime
root@emojirades-backup:~# cat /etc/timezone
Etc/UTC
root@emojirades-backup:~# date
Sun Feb  6 11:54:57 Australia 2022
root@emojirades-backup:~# TZ='Australia/Melbourne' date
Sun Feb  6 11:55:09 Australia 2022
root@emojirades-backup:~# TZ='UTC' date
Sun Feb  6 11:55:15 UTC 2022

Feel free to try emulate it yourself using the Dockerfile from this repo.

$ docker inspect emojirades-backup
...
        "HostConfig": {
            "Binds": [
                "/var/run/docker.sock:/var/run/docker.sock:ro",
                "/etc/timezone:/etc/timezone:ro",
                "/etc/localtime:/etc/localtime:ro"
            ],
        },
...
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/run/docker.sock",
                "Destination": "/var/run/docker.sock",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/etc/timezone",
                "Destination": "/etc/timezone",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/etc/localtime",
                "Destination": "/etc/localtime",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ]
...

michael-robbins avatar Feb 06 '22 11:02 michael-robbins

I hate to metoo on an issue, but given the age on this I'll risk chiming in that I experience this problem as well (TZ setting is ineffective, with both /etc/localtime and /etc/timezone bind mounted in). PR #52 was closed without comment. I'd love to see this fixed!

davidski avatar Dec 30 '22 01:12 davidski