问题描述
我使用 Ubuntu 16.04 映像创建了一个 Docker 容器.
I have created a Docker container using the Ubuntu 16.04 image.
docker run -it -d --name containername -v /var/www/public --privileged ubuntu
创建容器后,我检查了容器内的日期:
after creating the container, I checked the date inside the container:
$ date
Tue Oct 25 08:10:34 UTC 2016
但是,我需要它来使用 Asia/Kolkata 时区.所以我尝试更改 /etc/timezone
文件,然后 docker stop
和 docker start
容器,但 它不起作用.它仍然显示相同的时间.
But, I need it to use the Asia/Kolkata timezone. So I tried changing the /etc/timezone
file, then docker stop
and docker start
the container, but it doesn't work. It still shows the same time.
Docker容器创建后如何更改时区?
How can I change the time zone in the Docker container after creating it?
推荐答案
更新 /etc/timezone
是通常的方式,但是有一个 Xenial 中的错误 这意味着它不起作用.
Updating /etc/timezone
is the usual way, but there's a bug in Xenial which means that doesn't work.
相反,您需要创建一个从所需时区到 etc/localtime
的链接:
Instead you need to create a link from the desired timezone to etc/localtime
:
FROM ubuntu:xenial
RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
这篇关于Ubuntu 16.04 映像中的 Docker 时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!