LoginSignup
42
37

More than 5 years have passed since last update.

Dockerの時刻

Posted at

Dockerコンテナの時刻

Dockerコンテナを通常立ち上げると、時刻はUTCになってしまう。

# docker run -it --name homma01 centos /bin/bash
[root@dcd3aad6428e /]# date
Wed Aug 19 15:10:31 UTC 2015

JSTを使用したい

やっぱり時刻はJSTにしたい。
2つの方法があるみたいです。

参考情報は、Will docker container auto sync time with the host machine?です。

  • -v /etc/localtime:/etc/localtime:ro
  • -e "TZ=Asia/Tokyo"

/etc/localtimeをマウントする方法

-vオプション
# docker run -it --name homma01 -v /etc/localtime:/etc/localtime:ro centos /bin/bash
[root@d1698b83d04a /]# 
[root@d1698b83d04a /]# date
Thu Aug 20 00:09:19 JST 2015

環境変数で渡す方法

-eオプション
# docker run -it --name homma03 -e "TZ=Asia/Tokyo" centos /bin/bash 
[root@fbd2a720e5f4 /]# 
[root@fbd2a720e5f4 /]# date
Thu Aug 20 00:15:07 JST 2015

ログを出力必要がある場合、どちらかを指定しておきたい。
いずれ標準で、マウントされそうな予感がする。

42
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
37