4
alphine镜像中timezone的设定
source link: https://zhangrr.github.io/posts/20211103-alphine_timezone/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Alphine镜像中timezone的设定
2021-11-03
1 分钟阅读
我们都喜欢用 alphine 的镜像做底包,来生产自己的镜像
alphine 的底包的时间设定就非常重要了
直接给出 Dockerfile
FROM alpine:3.12
# latest certs
RUN apk add ca-certificates --no-cache && update-ca-certificates
# timezone support
ENV TZ=Asia/Shanghai
RUN apk add --update tzdata --no-cache &&\
cp /usr/share/zoneinfo/${TZ} /etc/localtime &&\
echo $TZ > /etc/timezone
# install chrony and place default conf which can be overridden with volume
RUN apk add --no-cache chrony && mkdir -p /etc/chrony
COPY chrony.conf /etc/chrony/.
# port exposed
EXPOSE 123/udp
# start
CMD [ "/usr/sbin/chronyd", "-d", "-s"]
时间设定重要的就是下面这几行
# timezone support
ENV TZ=Asia/Shanghai
RUN apk add --update tzdata --no-cache &&\
cp /usr/share/zoneinfo/${TZ} /etc/localtime &&\
echo $TZ > /etc/timezone
还有如果在 image: maven:3.5-jdk-8-alpine 这种镜像里,无论怎么改时间都不是东八区,可以试试下面的命令:
export COMMIT_TIME=$(TZ=CST-8 date +%F-%H-%M)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK