我尝试在运行时使用以下命令同步主机和容器之间的时区:
docker run -v $(pwd)/Data:/code/Data -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro --restart unless-stopped intermediateservice在运行docker logs命令时,这似乎不起作用:
docker logs -f -t zen_blackwell |tee output.log生成时间戳(大约落后2小时):
2021-01-13T10:43:22.372893697Z Ready...这是不正确的,因为运行timedatectl命令来检查主机上的当前时间(Ubuntu 18.04 LTS - Bionic Beaver)会产生:
timedatectl
Local time: Wed 2021-01-13 12:51:00 SAST
Universal time: Wed 2021-01-13 10:51:00 UTC
RTC time: Wed 2021-01-13 10:51:02
Time zone: Africa/Johannesburg (SAST, +0200)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no这里我漏掉了什么?
发布于 2021-01-14 16:07:21
你可以看看this answer
For the docker run -e TZ={timezone} workaround to work tzdata of course has to be installed in the container you’re trying to run.
What I was initially looking for (Docker container automatically having same timezone as host system) can be achieved through an ugly hack in the run script.
It can query geoip.ubuntu.com 172 (or any other geo IP database) once it is started on the new network and then set the server’s timezone based on the response:
https://askubuntu.com/a/565139askubuntu代码片段如下所示:
echo "Setting TimeZone..."
export tz=`wget -qO - http://geoip.ubuntu.com/lookup | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'` && timedatectl set-timezone $tz
export tz=`timedatectl status| grep Timezone | awk '{print $2}'`
echo "TimeZone set to $tz"https://stackoverflow.com/questions/65700649
复制相似问题