如何調整Docker container的系統時區

大部份container

由於Docker container預設時區為UTC,但因為在台灣的時區必須為Taipei,以下分享改的方式。

下述指令一次貼上執行

TZ=Asia/Taipei
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

檢查時區

ls -l /etc/localtime
#/etc/localtime -> /usr/share/zoneinfo/Asia/Taipei

date

同理,如需改其他國家的時區,也是一樣的方式喔!

純Ubuntu container

下述指令一次貼上執行

apt-get update && \
    apt-get install -yq tzdata && \
    ln -fs /usr/share/zoneinfo/Asia/Taipei /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *