Sync timezone of the container with the timezone of the host

Hi All,

How is it possible to synchronise the timezone of my Application’s container with the host’s timezone?

According to answers on other websites (like: https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes/683651), the right way to set the timezone is to:

  1. Ensure /etc/timezone is the same (either copy it with docker cp or mount)
  2. Create a symlink inside the container like:
export TZ=`cat /etc/timezone`
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime

I tried with mounting /etc/timezone and creating the symlink with the lines above right at the beginning of the container’s entrypoint. But this doesn’t work.

After some investigation, it turned out that appcenter deletes both files and then copies them from the host:

Since /etc/localtime has to be a symlink, this code seems to be incorrect. appcenter.log shows:

Error response from daemon: Error processing tar file(exit status 1): invalid symlink "/usr/share/zoneinfo/Europe/Zurich" -> "../usr/share/zoneinfo/
Europe/Zurich"

Is this a bug? Is there a simple workaround for this?

Any help would be appreciated.
Regards,
Balazs

Mastodon