LoginSignup
23
23

More than 5 years have passed since last update.

dockerコンテナ上の時刻同期について(NTP不使用)

Posted at

Dockerコンテナ

海外のimagesをダウンロードしてくると、時刻がUTCになっていたりlocateがJPN以外になっています。

このままだと、Dockerコンテナ上のログファイルなどの時刻がまともに取得できません。

NTPは使えない

NTP同期を行うためにはntpdをコンテナ内で起動する必要がありますが、1プロセス=1コンテナを原則とするDockerではntpdを起動すると他のことができなくなります。
※複数プロセスを1コンテナ内で起動する方法はいくつかありますが

結論:/etc/localtimeを使う

docker run -d -v /etc/localtime:/etc/localtime:ro hogehoge

上記のように-v /etc/localtime:/etc/localtime:roを使用します。

解説

/etc/localtimeはtimezoneのファイルのシンボリックリンクです

[root@master ~]# ls -ltr /etc/localtime lrwxrwxrwx. 1 root root 32  6月  4 14:23 /etc/localtime -> ../usr/share/zoneinfo/Asia/Tokyo

23
23
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
23
23