I have created a Docker container using the Ubuntu 16.04 image.
docker run -it -d --name containername -v /var/www/public --privileged ubuntu
after creating the container, I checked the date inside the container:
$ date
Tue Oct 25 08:10:34 UTC 2016
But, I need it to use the Asia/Kolkata timezone. So I tried changing the /etc/timezone
file, then docker stop
and docker start
the container, but it doesn't work. It still shows the same time.
How can I change the time zone in the Docker container after creating it?
In ubuntu 16.04 i was missing tzdata so i had to install it. Working solution was
As said here, the secret is that
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: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.