容器设置时区
命令行
docker run -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro your_image
Dockerfile
# 设置时区环境变量
ENV TZ=Asia/Shanghai
# 复制主机的时区文件到容器内
COPY /etc/localtime /etc/localtime
COPY /etc/timezone /etc/timezone
Docker Compose
services:
your_service:
image: your_image
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
environment:
- TZ=Asia/Shanghai