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?
I took this approach:
Copy file /etc/localtime somewhere.
Open it and find the this number (highlighted with yellow)
-3 corresponds to Moscow time. For Berlin set -1 . If you need positive value, set UTC2
Copy and modify /etc/timezone according to your time zone.
Result:
If you use docker-compose, just add one line to your
docker-compose.yml
file.version: '3'
My issue has been solved with this very simple solution (https://serverfault.com/a/826222) : Add timezone in environment variable.
The command is
docker run -e TZ=Europe/Amsterdam ...
Or, using docker-compose, like I do :
In my case, no more tzdata needed, or volume share with /etc/timezone & /etc/localtime.
Hope it helps !
Updating
/etc/timezone
is the usual way, but there's a bug in Xenial which means that doesn't work.Instead you need to create a link from the desired timezone to
etc/localtime
:SOLVED:
Try:
You have to do
rm /etc/localtime
because of the Ubuntu bug.