-1

我使用命令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 中的命令不起作用。所以,请教我如何正确更改时区,谢谢。

4

2 回答 2

1

我假设dpkg-reconfigure -f noninteractive tzdata做错了什么。

我建议设置ENV TZ=Asia/Shanghai和/或运行

ln -s -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
于 2018-06-14T15:03:09.143 回答
0

尝试使用

ENV TZ=Asia/Singapore

在你的 dockerfile 中。它将全球环境时区设置为适当的时区。

于 2018-06-14T14:31:04.407 回答