<p>I am currently deploying <a href="https://docs.openfaas.com/" rel="nofollow noreferrer">openfaas</a> on my local virtual machine's <a href="https://kubernetes.io/" rel="nofollow noreferrer">kubernetes</a> cluster. I found that the time zone of the container started after publishing the function is inconsistent with the host machine. How should I solve this problem?</p>
<pre class="lang-sh prettyprint-override"><code>[root@k8s-node-1 ~]# date
# Host time
2021年 06月 09日 星期三 11:24:40 CST
[root@k8s-node-1 ~]# docker exec -it 5410c0b41f7a date
# Container time
Wed Jun  9 03:24:40 UTC 2021
</code></pre>

silentao
<p>As <strong>@coderanger</strong> pointed out in the comments section, the timezone difference is not related to <code>OpenFaaS</code>.<br />
It depends on the image you are using, most of the images use <code>UTC</code> timezone.
Normally this shouldn't be a problem, but in some special cases you may want to change this timezone.</p>
<p>As described in this <a href="https://bobcares.com/blog/change-time-in-docker-container/" rel="nofollow noreferrer">article</a>, you can use the <code>TZ</code> environment variable to set the timezone of a container (there are also other ways to change the timezone).</p>
<p>If you have your own <code>Dockerfile</code>, you can use the <a href="https://docs.docker.com/engine/reference/builder/#env" rel="nofollow noreferrer">ENV</a> instruction to set this variable:<br />
<strong>NOTE:</strong> The <code>tzdata</code> package has to be installed in the container for setting the <code>TZ</code> variable.</p>
<pre><code>$ cat Dockerfile
FROM nginx:latest
RUN apt-get install -y tzdata
ENV TZ=&quot;Europe/Warsaw&quot;

$ docker build -t mattjcontainerregistry/web-app-1 .
$ docker push mattjcontainerregistry/web-app-1
$ kubectl run time-test --image=mattjcontainerregistry/web-app-1
pod/time-test created

$ kubectl exec -it time-test -- bash
root@time-test:/# date
Wed Jun  9 17:22:03 CEST 2021
root@time-test:/# echo $TZ
Europe/Warsaw
</code></pre>
