Docker time zone timezone issues

Original: Docker time zone timezone issues

Linux Time Type

  • In the Unix-like machine /usr/share/zoneinfo/in the document calls for all code ZONEINFOlocation of the data, when you want to see what time zone settings, you can go directly to the inside look at the name.
    time_zone time zone

docker time, time zone issues

The docker container default time utc

docker-compose at startup settings:

Setting time within the container to the host:

volumes:
  - /etc/localtime:/etc/localtime:ro
  - /etc/timezone:/etc/timezone:ro   # 这个只在Linux上有
  # “ro”的意思是只读(read-only)模式,可以保证其挂载卷不被 Docker 容器内部文件系统配置所覆盖

# 通过环境变量设置时区    
environment:
  - TZ=Asia/Shanghai   # 设置容器时区为CST

  
  
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

generating a mirror disposed dockerfile

RUN echo "Asia/Shanghai" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

# 已上是 Ubuntu 修改时区的命令。
# Docker 默认使用 Ubuntu系统。
# 如果你的自定义镜像使用的是其他发行版,那么这里的命令也要改变

  
  
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

When the container starts directly

docker run -v /etc/localtime:/etc/localtime <IMAGE:TAG>

  
  
 
 
  • 1

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12348302.html