Timezone in container


I am sorry to ask again stupid questions but I didn’t find any answer.

After I created and configured my first container I noticed that the time zone is set to UTC. I set the Europe/Berlin time zone to the default profile but this didn’t change the zone for the already created container.

Afterwards I used the following command in order to add the timezone to the container

lxc config set Ubuntu2004-Master environment.TZ Europe/Berlin

I checked the time zone with the following command

lxc exec Ubuntu2004-Master -- date                                                                                                                                                                       
Sat Jul 17 17:16:43 CEST 2021

So all looks fine, but when I use the lxc shell command and then use the date command within the container the time still seems to be set to the UTC time.

Sat Jul 17 15:17:03 UTC 2021

Does anyone have an idea what I am doing wrong ?

lxc shell is a built-in alias for lxc exec NAME -- su -l

su goes through the PAM library which can strip the environment variables causing what you’re seeing. You can confirm it with env | grep TZ in both cases.

Thank you for the detailed description.

The lxc shell command does not provide me any output for env | grep TZ while the lxc exec provide me the TZ.

I don’t know whether there is an answer for the question but what is in general the correct (best) way to jump into the container.

lxc shell <containername


lxc exec <container-name> -- sudo /bin/zsh

I personally prefer the second as lxc shell comes with a bit of overhead and as you’ve noticed may clear the environment and do other fun things.

For this particular case, setting TZ in /etc/environment inside the container should make the shell case happy too.