The simplest solution appears to be to run your container with the -v /etc/localtime:/etc/localtime:ro option. Thus:
#run without tz info:
docker run --rm -t -i ubuntu date
Wed Apr 2 18:40:07 UTC 2014
# run with tz info:
docker run --rm -t -i -v /etc/localtime:/etc/localtime:ro ubuntu date
Wed Apr 2 11:40:29 PDT 2014
If you are running 风筝, which is now the suggested mechanism for getting up and running on Docker in OSX, you will have to periodically run this command:
进入后,请注意,moby login只是 root,没有密码。完成后,CTRL-A、 D 将断开与屏幕会话的连接。
NOTE: This used to be documented on 解决 Mac 故障的码头工人 but that seems to have been taken down. I was lucky enough to be shown it while at Dockercon 2016. It seems Docker is trying to abstract the VM completely out of the experience, which explains why it's no longer documented.
If your system does not have access to an NTP server, then after a hibernate the time seen by Docker for Mac may be considerably out of sync with the host. Furthermore, the time may slowly drift out of sync during use. To manually reset the time after hibernation, run:
If you prefer the TZ solution then you may be surprised to see UTC time displayed despite your request for your own timezone (it's currently 11:09 CDT):
$ docker run --rm -it -e "TZ=America/Chicago" ubuntu date
Mon Oct 26 16:09:04 America 2020
实验上,你似乎需要 POSIX TZ格式:
$ docker run --rm -it -e "TZ=CST6CDT" ubuntu date
Mon Oct 26 11:09:17 CDT 2020