背景
我寫了個py腳本赡模,打包成鏡像執(zhí)行。
依賴時間執(zhí)行授瘦,容器里默認時間是錯誤的。我需要東八區(qū)時間
這里提供了烏班圖和centos的解決方案竟宋。
下面的例子還包含了:修改國內(nèi)源提完,centos中文的支持問題。
解決
centos版本
FROM centos:7
#設(shè)置時區(qū)
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
# 設(shè)置時區(qū)
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" ]