Docker image for tinkering how to set the local time in a container
249
localtimelab is a Docker container for tinkering how to set the local time/time zone of a Docker container.
While working with different Docker containers I realized that there are –at least– two ways to set the local time/time zone in a container:
TZ (example -e TZ="Asia/Phnom_Penh")./etc/localtime on the host (-v /etc/localtime:/etc/localtime:ro).The first way seems to be the most common way to set the local time/time zone. The second way does not work on macOS and Windows host, because /etc/localtime is not available on these systems.
I had already "added" the way via -e TZ="Europe/Berlin" to an image (there was nothing to do except adding the repository tzdata...).
After stumbling over this thread in the linuxserver.io Disourse I wanted to dig a little bit deeper.
It is a minimal image with an Alpine Linux as base, one additional image (tzdata) and a script, which is calling date (Yes, I could also put date directly into the CMD…).
Just run the container with these four configurations and see:
docker run --rm \
thoschworks/localtimelab
docker run --rm \
-e TZ="Asia/Phnom_Penh" \
thoschworks/localtimelab
docker run --rm \
-v /etc/localtime:/etc/localtime:ro \
thoschworks/localtimelab
docker run --rm \
-e TZ="Asia/Phnom_Penh" \
-v /etc/localtime:/etc/localtime:ro \
thoschworks/localtimelab
The first three examples work as expected. To my big surprise -e TZ="…" supersedes -v /etc/localtime … in the fourth example.
Content type
Image
Digest
Size
4.7 MB
Last updated
about 6 years ago
docker pull thoschworks/localtimelab