Docker Timezone in Ubuntu 16.04 Image

Try:

echo "Asia/Kolkata" > /etc/timezone
rm -f /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

You have to do rm /etc/localtime because of the Ubuntu bug.


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:

FROM ubuntu:xenial     
RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata

In ubuntu 16.04 i was missing tzdata so i had to install it. Working solution was

    ENV TZ 'Europe/Tallinn'
    RUN echo $TZ > /etc/timezone && \
    apt-get update && apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean

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:

ENV TZ=America/Los_Angeles
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.