乌班图+centos容器时区修正

背景

我写了个py脚本,打包成镜像执行。
依赖时间执行,容器里默认时间是错误的。我需要东八区时间

这里提供了乌班图和centos的解决方案。

下面的例子还包含了:修改国内源,centos中文的支持问题。

解决

centos版本

FROM centos:7

#设置时区
ENV TIME_ZONE Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime



RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

RUN yum clean all
RUN yum makecache


RUN yum update -y && \  
yum install -y python3-pip python3-dev 


#解决中文乱码问题
RUN yum -y install kde-l10n-Chinese && yum -y reinstall glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV LANG en_US.utf8


COPY ./requirements.txt /requirements.txt

COPY ./fs.py /fs.py

COPY ./pip.conf /etc/pip.conf

WORKDIR /

RUN pip3 install -r requirements.txt -i https://pypi.doubanio.com/simple

ENTRYPOINT [ "python3" ]

CMD [ "/fs.py" ] 


乌班图版本

FROM ubuntu:16.04


COPY ./sources.list /etc/apt/sources.list

RUN rm -Rf /var/lib/apt/lists/*

RUN apt-get update -y && \  
apt-get install -y python3-pip python3-dev --allow-unauthenticated


# 设置时区
RUN apt-get -y update && DEBIAN_FRONTEND="noninteractive" apt -y install  tzdata
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


COPY ./requirements.txt /requirements.txt

COPY ./fs.py /fs.py

COPY ./pip.conf /etc/pip.conf

WORKDIR /

RUN pip3 install -r requirements.txt -i https://pypi.doubanio.com/simple

ENTRYPOINT [ "python3" ]

CMD [ "/fs.py" ] 


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容