1、Dockerfile中创建时区文件
CentOS
FROM centos
ENV TZ=Asia/Shanghai
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone
Alpine
FROM alpine
ENV TZ=Asia/Shanghai
RUN apk add --no-cache tzdata \
&& echo "${TZ}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& apk del tzdata \
# 可选,上面已指定no-cache
&& rm -rf /var/cache/apk/*
2、运行容器时挂载主机时区
方式1
挂载本地 /etc/localtime
到容器内:
docker run -it -v /etc/localtime:/etc/localtime centos /bin/sh
方式2
挂载本地 /usr/share/zoneinfo/Asia/Shanghai
到容器内
docker run -it -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime centos /bin/sh
标签:容器,TZ,Shanghai,share,etc,内时区,&&,Docker,localtime
From: https://www.cnblogs.com/gaozejie/p/17137246.html