0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dockerコンテナ:alpineでのタイムゾーン設定

Posted at

タイムゾーンがUTCからJSTに変わってくれない

いろいろ経緯があってalpine使用中に顕現した問題なのですが、
何とか解決。
他のLinuxでは検証していません。
悪しからず。

最初の設定

FROM node:23-alpine

# タイムゾーンパッケージのインストール
RUN apk add --no-cache tzdata

# タイムゾーンを日本時間に設定
ENV TZ=Asia/Tokyo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

結局の設定

FROM node:23-alpine

# タイムゾーンパッケージのインストール
RUN apk add --no-cache tzdata

# タイムゾーンを日本時間に設定
RUN ln -snf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && echo Asia/Tokyo > /etc/timezone

環境変数の定義をやめてシンボリックを設定。

なぜか?

  • 環境変数の設定内容
    TZ=Asia/Tokyo このような形式だとNG
    TZ="NZST-12:00:00NZDT-13:00:00,M9.5.0,M4.1.0/3" このような形式だとOK
    じゃあ、東京はどうなの?と思ったけど、うまくいかなくて一旦断念。
  • さらに環境変数を設定したときの挙動
    環境変数を設定すると/etc/localtimeは参照しない。
    環境変数の設定がtzsetの形式に合致しない場合、未設定状態と判定し、UTCになる。
    結局、環境変数の設定をやめて、/etc/localtimeに対して、シンボリックリンクを貼ることで対応しました。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?