配置Dockerfile镜像时修改,这样打包出来的镜像文件是需要的时区的。
不然就会如上图所示,导致获取时间无论哪个时区都是utc的问题,这样在代码获取时间的时候,会出现时间不同步,导致后续的一系列未知问题出现。
所以建议在每个docker file构建的时候,推荐安装tzdata
Apline
FROM alpine:latest
ENV TZ=Asia/Shanghai \
LANG=zh_CN.UTF-8
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && apk update
RUN apk add --no-cache mysql mysql-client tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Centos
未受影响,可以不安装
Ubuntu
FROM debian:10.13
RUN echo '' > /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian/ buster main non-free contrib' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian-security buster/updates main' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib' >> /etc/apt/sources.list
RUN apt-get clean && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y wget locales apt-utils tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "End basic tools"
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
locale-gen
Ubuntu
FROM ubuntu:16.04
ENV TZ=Asia/Shanghai \
LANG=zh_CN.UTF-8
RUN echo '' > /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse' >> /etc/apt/sources.list
USER root
RUN apt-get clean && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y wget locales apt-utils tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "End basic tools"
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
locale-gen
若文章对你有帮助,可以点赞或打赏支持我们。发布者:Aurora,转载请注明出处:http://61.174.243.28:13541/AY-knowledg-hub/docker%e9%95%9c%e5%83%8f%e4%b8%ad%ef%bc%8c%e9%85%8d%e7%bd%ae%e6%97%b6%e5%8c%ba%e4%b8%80%e7%9b%b4%e4%b8%bautc%e7%9a%84%e9%97%ae%e9%a2%98/