-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
docker container默认是UTC时间的,如果要使用北京时间需要修改时区,有以下几种方式:
1. 使用dpkg-reconfigure命令
$ docker run -i -t ubuntu bash
root@1f8ccb4c3dc1:/# date
Wed Sep 10 16:02:38 UTC 2014
root@1f8ccb4c3dc1:/# dpkg-reconfigure tzdata
Current default time zone: 'Asia/Shanghai'
Local time is now: Thu Sep 11 00:02:50 CST 2014.
Universal Time is now: Wed Sep 10 16:02:50 UTC 2014.
root@1f8ccb4c3dc1:/# date
Thu Sep 11 00:02:52 CST 2014
root@1f8ccb4c3dc1:/#
2. 挂载使用系统/etc/localtime
$ docker run -i -t -v /etc/localtime:/etc/localtime ubuntu bash
root@6213cd50d722:/# date
Thu Sep 11 00:08:56 CST 2014
root@6213cd50d722:/#
旧版本的dockere可能文件是/etc/localtime:ro
,需要修改挂载方式为:-v /etc/localtime:/etc/localtime:ro
3. 直接覆盖/etc/localtime
$ docker run -i -t ubuntu bash
root@d4b926fb2c75:/# date
Wed Sep 10 16:11:15 UTC 2014
root@d4b926fb2c75:/# apt-get install -y wget > /dev/null 2>&1
root@d4b926fb2c75:/# wget http://ma6174.u.qiniudn.com/localtime -O /etc/localtime -o /dev/null
root@d4b926fb2c75:/# date
Thu Sep 11 00:13:05 CST 2014
root@d4b926fb2c75:/#