docker-compose:容器时区

Hel*_*röm 1 timezone docker docker-compose

我正在使用Docker Compose在我的开发环境中运行我的堆栈,但是我遇到了一个问题,即容器中的时区比我自己的时区晚了一个小时,破坏了关键任务,使开发变得非常困难。

我认为这将是一个普遍的问题,因此我进行了广泛搜索,但是我发现的仅有的两个解决方案不起作用(不起作用:无效)。

我已经尝试了两件事:

尝试1-从主机
卷进行符号链接通过尝试挂载/etc/timezone/etc/localtime作为ro卷,我希望容器与主机具有相同的时区。没有效果。

尝试2-设置变量,而command
不是让Docker Compose使用ENTRYPOINTmy中指定的变量,而是在-file中Dockerfile设置:commanddocker-compose.yml

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"
Run Code Online (Sandbox Code Playgroud)

同样,完全没有效果。

是否没有在Docker容器中设置时区的官方方法?我觉得这应该是比我更多的用户的关键问题。

谢谢。

编辑:根据要求dockerfilecore/documents-project中。

# 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
Run Code Online (Sandbox Code Playgroud)

小智 5

我在时区方面也遇到了问题,这对我来说很有效:

environment:
  - TZ=Europe/Stockholm
Run Code Online (Sandbox Code Playgroud)