Docker时区在Ubuntu 16.04图像
我已经使用Ubuntu 16.04镜像创build了Docker conatainer。
docker运行-it -d –name容器名-v / var / www / public –privileged ubuntu
创build容器后,我在容器内检查date
#date
星期二10月25日08:10:34 UTC 2016
但是,我需要设立亚洲/加尔各答 ,我试图改变
在/ etc /时区
然后文件停止并启动 Docker容器, 它不起作用。 仍然显示同一时间。
build议我如何更改docker容器中的时区在创build容器之后?
更新/etc/timezone
是常用的方法,但Xenial中存在一个错误,这意味着无法正常工作。
相反,你需要创build一个从所需的时区到etc/localtime
的链接:
FROM ubuntu:xenial RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
尝试:
echo "Asia/Kolkata" > /etc/timezone rm /etc/localtime dpkg-reconfigure -f noninteractive tzdata
由于Ubuntu的bug,你必须做rm /etc/localtime
。
在Ubuntu 16.04我缺lesstzdata,所以我不得不安装它。 工作解决scheme是
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
解决了:
FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y software-properties-common apt-utils locales tzdata RUN echo "tzdata tzdata/Areas select Europe" > timezone.txt RUN echo "tzdata tzdata/Zones/Europe select Rome" >> timezone.txt RUN debconf-set-selections timezone.txt RUN rm /etc/timezone RUN rm /etc/localtime RUN dpkg-reconfigure -f noninteractive tzdata