6

如何设置容器中的时区

 3 years ago
source link: https://www.lujun9972.win/blog/2018/09/23/%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E5%AE%B9%E5%99%A8%E4%B8%AD%E7%9A%84%E6%97%B6%E5%8C%BA/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何设置容器中的时区

之前以为设置容器时区很简单,跟设置Linux时区一样的操作就行.

但是实际没有那么简单,因为有些基础镜像,比如Ubuntu是没有安装tzdata的, 而当在Dockerfile用apt来安装tzdata时会发现这玩意安装好后居然要手工选择一次地域. 这就很尴尬了。

万幸的是,主机一般都是安装了tzdata的,因此实际上我们可以将主机上的 zoneinfo 文件直接挂载到容器中的 /etc/localtime 就行了

我们可以比较一下

docker run --rm ubuntu date
docker run --rm -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro ubuntu date
Sat Sep 22 22:54:45 UTC 2018
Sun Sep 23 06:54:46 CST 2018

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK