I use command apt-get install -y tzdata && echo Asia/Shanghai > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
to change timezone to UTC+8,but it doesn't work。My Dockerfile as follows:
FROM ubuntu:xenial
MAINTAINER Leon.Gan
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main" >/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main" >>/etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main" >>/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main" >>/etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial universe" >>/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe" >>/etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe" >>/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe" >>/etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main" >>/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main" >>/etc/apt/sources.list \
&& echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe" >>/etc/apt/sources.list \
&& echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe" >>/etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y locales \
&& locale-gen zh_CN.UTF-8 \
&& apt-get install -y tzdata \
&& echo Asia/Shanghai > /etc/timezone \
&& dpkg-reconfigure -f noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*
ENV LC_ALL "zh_CN.UTF-8"
ENV LANG "zh_CN.UTF-8"
CMD ["/bin/bash"]
After build image, I enter the container, run command cat /etc/timezone
,the content is still Etc/UTC. It means my command echo Asia/Shanghai > /etc/timezone
in Dockerfile is not work. So, plz teach me how to change the timezone correctly, thanks.
I assume dpkg-reconfigure -f noninteractive tzdata
does something wrong.
I recommend to either set ENV TZ=Asia/Shanghai
and/or to run
ln -s -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime