我使用命令apt-get install -y tzdata && echo Asia/Shanghai > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
将时区更改为UTC+8,但它不起作用。我的Dockerfile如下:
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"]
构建镜像后进入容器,运行命令cat /etc/timezone
,内容还是Etc/UTC。这意味着我echo Asia/Shanghai > /etc/timezone
在 Dockerfile 中的命令不起作用。所以,请教我如何正确更改时区,谢谢。