Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux docker容器内的时区ID不正确_Linux_Docker_Centos_Timezone - Fatal编程技术网

Linux docker容器内的时区ID不正确

Linux docker容器内的时区ID不正确,linux,docker,centos,timezone,Linux,Docker,Centos,Timezone,我已经从基础Centos7映像创建了一个docker映像,在从中运行容器时,时间和时区与主机不同步。为容器指定与主机相同的时区。在运行容器时,我使用“-v”参数将/etc/timezone和/etc/localtime从主机装载到容器。 使用此命令运行容器后,我在容器和主机中得到以下内容: 对于运行timedatectl的docker容器: [root@d7a24c723f6a /]# timedatectl Local time: Tue 2017-08-01 10:28:30 I

我已经从基础Centos7映像创建了一个docker映像,在从中运行容器时,时间和时区与主机不同步。为容器指定与主机相同的时区。在运行容器时,我使用“-v”参数将/etc/timezone和/etc/localtime从主机装载到容器。 使用此命令运行容器后,我在容器和主机中得到以下内容:

对于运行timedatectl的docker容器:

[root@d7a24c723f6a /]# timedatectl
      Local time: Tue 2017-08-01 10:28:30 IST
  Universal time: Tue 2017-08-01 04:58:30 UTC
        RTC time: n/a
       Time zone: UTC (IST, +0530)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
[root@indiadev72 ~]# timedatectl
      Local time: Tue 2017-08-01 10:27:29 IST
  Universal time: Tue 2017-08-01 04:57:29 UTC
        RTC time: Tue 2017-08-01 04:57:29
       Time zone: Asia/Kolkata (IST, +0530)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
对于运行timedatectl的主机:

[root@d7a24c723f6a /]# timedatectl
      Local time: Tue 2017-08-01 10:28:30 IST
  Universal time: Tue 2017-08-01 04:58:30 UTC
        RTC time: n/a
       Time zone: UTC (IST, +0530)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
[root@indiadev72 ~]# timedatectl
      Local time: Tue 2017-08-01 10:27:29 IST
  Universal time: Tue 2017-08-01 04:57:29 UTC
        RTC time: Tue 2017-08-01 04:57:29
       Time zone: Asia/Kolkata (IST, +0530)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
我不知道为什么我的docker容器不能获取主机的时区

编辑: 另外,在运行我的一些测试用例时,我能够看到应用程序将timezoneid读取为“GMT+530”,而不是亚洲/加尔各答。虽然GMT+530确实是亚洲/加尔各答,但由于容器中的时区ID不匹配,我的测试用例失败了。
也许这只是timezoneID问题,而容器正在选择正确的时间。有人能在这里帮忙吗?

请将输出格式化为代码,这样就不会合并到一行中,这样有帮助吗?另外,docker映像中是否安装了
tzdata
包?我已经这样做了,是的,映像中安装了tzdata包?问题似乎只是timezoneID,我的应用程序预计timezoneID为Asia/Kolkata,但其读数为“GMT+530”。它们实际上是相同的,但ID是不同的。您可以通过运行timedatectl来签入docker映像吗?请将输出格式化为代码,这样它就不会合并到一行中。这样有帮助吗?另外,docker映像中是否安装了
tzdata
包?我已经这样做了,是的,映像中安装了tzdata包?问题似乎只是timezoneID,我的应用程序预计timezoneID为Asia/Kolkata,但其读数为“GMT+530”。它们实际上是相同的,但ID是不同的。你能通过运行timedatectl来签入你的docker镜像吗?