I have created a docker image from the base Centos7 image and while running the container from it, the time and timezone were not in sync with my host. To give the container the same timezone as that of the host. I mounted /etc/timezone and /etc/localtime from the host to the container using the '-v' argument while running the container. After running the container with this, this is what i get inside the container and host:

For docker container running timedatectl:

[root@d7a24c723f6a /]# timedatectl Local time: Tue 2017-08-01 10:28:30 IST Universal time: Tue 2017-08-01 04:58:30 UTC RTC time: n/a Time zone: UTC (IST, +0530) NTP enabled: n/a NTP synchronized: no RTC in local TZ: no

For host running timedatectl:

[root@indiadev72 ~]# timedatectl Local time: Tue 2017-08-01 10:27:29 IST Universal time: Tue 2017-08-01 04:57:29 UTC RTC time: Tue 2017-08-01 04:57:29 Time zone: Asia/Kolkata (IST, +0530) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a

I am not sure why my docker container is not able to take the timezone of the host.

EDIT: Also while running some of my test cases, i am able to see that the application is reading timezoneid as 'GMT+530' instead of Asia/Kolkata. While GMT+530 is indeed Asia/Kolkata but due the timezone ID mismatch inside the container my test cases are failing. Maybe its just the timezoneID issue and the container is picking up the correct time. Can someone please help here?

1 Answer 1


The case is dpkg-reconfigure tzdata simply creates /etc/localtime as a copy, hardlink or symlink (a symlink is preferred) to a file in /usr/share/zoneinfo. So it is possible to do this entirely from your Dockerfile. Consider:

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

And as a bonus, TZ will be set correctly in the container as well.

This is also distribution-agnostic, so it works with pretty much anything Linux.

The original answer: https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes

  • 2
    This is a copied answer from stackoverflow. Please mention the source of answers when youre copying it to give due credit to the original posters. Anyways, i have already created a symlink and it just doesnt get te timezone ID right.
    – lakshayk
    Commented Aug 2, 2017 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.