Synchronize timezone from host to Docker container

Viewed 1790

I'm surprised there seems to be no easy and cross-platform way to synchronize the timezone from host to a Docker container at runtime. So, the timezone in the container should not be set when it's built but when it's started. So far I found the following two options:

a) docker run -v /etc/timezone:/etc/timezone:ro

b) docker run -e "TZ=Asia/Kolkata"

Both are a no-go for my use case. a) works only on Linux as there's no /etc/timezone on Windows and macOS. b) requires the user to manually set the desired timezone (i.e. the same as on the host).

Are these really all sensible options?

For the sake of completeness doing this at build time in the Dockerfile you'd use something like this I learned:

RUN sudo echo "America/New_York" > /etc/timezone
RUN sudo dpkg-reconfigure -f noninteractive tzdata

Side note: this is a copy of https://forums.docker.com/t/synchronize-timezone-from-host-to-container/39116 but I understand not every one with Docker know-how has an account there.

0 Answers
Related