我使用Ubuntu16.04映像创建了一个Docker容器。
docker run -it -d --name containername -v /var/www/public --privileged ubuntu
在创建容器之后,我检查了容器内的日期:
$ date
Tue Oct 25 08:10:34 UTC 2016
但是,我需要它使用亚洲/加尔各答时区。因此,我尝试更改/etc/timezone
文件,然后docker stop
和docker start
容器,但它不工作。它仍然显示相同的时间。
如何在创建后更改Docker容器中的时区?
发布于 2016-10-25 08:42:05
更新/etc/timezone
是通常的方法,但是有一个Xenial中的bug,这意味着它不能工作。
相反,您需要创建一个从所需时区到etc/localtime
的链接。
FROM ubuntu:xenial
RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
发布于 2017-06-19 10:22:04
在ubuntu16.04中,我丢失了tzdata,所以我不得不安装它。工作溶液
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
发布于 2017-04-14 04:51:54
尝试:
echo "Asia/Kolkata" > /etc/timezone
rm -f /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
您必须做rm /etc/localtime
,因为Ubuntu错误。
https://stackoverflow.com/questions/40234847
复制相似问题