Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker container修改时区 #9

ma6174 opened this issue Sep 10, 2014 · 0 comments


Copy link

commented Sep 10, 2014

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

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

旧版本的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 -O /etc/localtime -o /dev/null
root@d4b926fb2c75:/# date
Thu Sep 11 00:13:05 CST 2014

@ma6174 ma6174 added the docker label Sep 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.