Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to get local timezone inside container

📅 2019-Oct-02 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ docker, timezone ⬩ 📚 Archive

When you run a Docker container of Linux, you can notice that it uses UTC timezone by default:

$ docker run -it ubuntu
root@bd08a5ee9d0b:/# date
Thu Oct  3 05:13:25 UTC 2019

This can be inconvenient if you plan to use the container to run applications that log with timestamps. Such timestamps would be confusing when you view them outside the container.

To run a Docker container of Linux with your local timezone, map your local /etc/localtime inside the container:

$ docker run -v /etc/localtime:/etc/localtime -it ubuntu
root@ce119be54aca:/# date
Wed Oct  2 22:16:03 PDT 2019

Tried with: Docker 18.09.6 and Ubuntu 18.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧