docker-compose:容器时区
我正在使用Docker Compose在我的开发环境中运行我的堆栈,但是我在容器中的时区有问题,比我自己的时区晚一个小时,打破了关键任务并使开发非常困难。
我认为这将是一个普遍的问题,所以我search了很多,但唯一的两个解决scheme,我发现不工作(不工作:没有效果)。
我试了两件事:
尝试1 – 从主机build立符号链接
通过尝试挂载/etc/timezone
和/etc/localtime
作为ro
volume,我希望容器与主机具有相同的时区。 没有效果。
尝试2 – 在command
设置variables
不要让Docker Compose使用我的ENTRYPOINT
指定的Dockerfile
,而是在Dockerfile
docker-compose.yml
文件中设置command
:
environment: - APPLICATION_ENV=dev-docker - TZ=Europe/Stockholm build: ../../core/document command: > sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && exec /go/bin/documents"
再次,根本没有效果。
有什么官方的方式在Docker容器中设置时区? 我觉得这应该是比我更多的用户的关键问题。
谢谢。
编辑 :从core/documents
的dockerfile
,按要求。
# This file is intended for use with the GitLab CI tool where the binary has already been built. FROM golang:1.9.2 # The binary is built and downloaded to the current directory by GitLab CI. COPY ./documents /go/bin # Run the program. ENTRYPOINT /go/bin/documents
我也遇到了时区的问题,对我来说这是个诀窍:
environment: - TZ=Europe/Stockholm