Docker相关操作系统镜像时区设置

198 阅读1分钟

centos7/ubuntu镜像时区设置

# 设置环境变量TZ,指定时区
ENV TZ=Asia/Shanghai
# 链接到/etc/localtime
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

debian镜像时区设置

# 设置环境变量TZ,指定时区
ENV TZ=Asia/Shanghai
 
# 安装时区数据,并链接到/etc/localtime
RUN apt-get update && \
    apt-get install -y tzdata && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone && \
    dpkg-reconfigure -f noninteractive tzdata && \
    rm -rf /var/lib/apt/lists/*

alpine镜像时区设置

# 容器使用的是alpine linux镜像,默认不含时区数据包
RUN apk add --no-cache tzdata
# 定义时区参数
ENV TZ=Asia/Shanghai
# 设置时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

fedora镜像时区设置

# 设置环境变量TZ,指定时区
ENV TZ=Asia/Shanghai

# 安装时区数据,并链接到/etc/localtime
RUN dnf -y install tzdata && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone && \
    dnf clean all