wiki:jazz/18-02-06

2018-02-06

docker

  • docker timezone 設定

[CASE 1] 在原本 Host OS 的 Time Zone 是 UTC/GMT 的環境上

~$ date; docker run --rm alpine date; docker run --rm -e TZ=Asia/Taipei alpine date; docker run --rm debian date; docker run --rm -e TZ=Asia/Taipei debian date; docker run --rm centos date; docker run --rm -e TZ=Asia/Taipei centos date
Tue Feb  6 06:36:36 UTC 2018
Tue Feb  6 06:36:36 UTC 2018
Tue Feb  6 06:36:37 GMT 2018
Tue Feb  6 06:36:37 UTC 2018
Tue Feb  6 14:36:38 CST 2018
Tue Feb  6 06:36:38 UTC 2018
Tue Feb  6 14:36:38 CST 2018

[CASE 2] 在原本 Host OS 的 Time Zone 是 Asia/Taipei(GMT+8) 的環境上

~]$ date; docker run --rm alpine date; docker run --rm -e TZ=Asia/Taipei alpine date; docker run --rm debian date; docker run --rm -e TZ=Asia/Taipei debian date; docker run --rm centos date; docker run --rm -e TZ=Asia/Taipei centos date
二  2月  6 14:40:42 CST 2018   <--- 原本 Host OS 是 GMT+8
Tue Feb  6 06:40:43 UTC 2018  <---- Alpine Docker 容器內預設是 UTC
Tue Feb  6 06:40:43 GMT 2018  <---- Alpine 容器內,縱使指定 TZ 環境變數也還是 GMT
Tue Feb  6 06:40:44 UTC 2018  <---- Debian Docker 容器內預設是 UTC
Tue Feb  6 14:40:44 CST 2018  <---- Debian 容器內,指定 TZ 環境變數變成 GMT+8
Tue Feb  6 06:40:44 UTC 2018  <---- CentOS Docker 容器內預設是 UTC
Tue Feb  6 14:40:45 CST 2018  <---- CentOS 容器內,指定 TZ 環境變數變成 GMT+8

[備忘] alpine 需要安裝 tzdata 套件才會生效

Last modified 7 years ago Last modified on Feb 6, 2018, 2:52:35 PM