[Docker] 在Container 中設定時區

利用 Docker image 建立 container 後, 有時會見到時區會設定為UTC-0, 所以時間上會有所出入.若要解決問題, 較早期的方是直接修改/etc/timezone, 使其設定時區. 然而在較新的版本就不可以修改. 因為它改了利用soft-link 指往/usr/share/zoneinfo/ 中進行. 若要修改則須要執行以下指令:

# Access to container in bash.
docker exec -ti <<Container_Name>> bash

# Set timezone
ln -snf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime && echo Asia/Hong_Kong > /etc/timezone

修改後輸入date 指令, 可以檢查是否已經修改成功.

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.