副标
Dockerize your Python Application
dockerfile python example
dockerfile python flask example
flask框架为例
Dockerfile
FROM alpine:latest
# 打标签
LABEL version="1.0" \
description="alpine:latest" \
maintainer="wwek<licoolgo@gmail.com>"
# 配置apk包加速镜像为阿里
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装一些基础包
RUN apk update \
&& apk upgrade \
&& apk add s6 \
&& apk add bash \
# && apk add nghttp2-dev \
&& apk add ca-certificates \
&& apk add wget \
# && apk add curl \
# && apk add tcpdump \
# && apk add bash-completion \
&& apk add iputils \
&& apk add iproute2 \
&& apk add libc6-compat \
&& apk add -U tzdata \
&& rm -rf /var/cache/apk/*
# 设置 操作系统时区
RUN rm -rf /etc/localtime \
&& ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 设置时区变量
ENV TIME_ZONE Asia/Shanghai
# 安装 python3、升级pip、setuptools
RUN apk add --no-cache python3 \
#&& apk add --no-cache python3-dev \
&& python3 -m ensurepip \
&& rm -r /usr/lib/python*/ensurepip \
&& pip3 install --default-timeout=100 --no-cache-dir --upgrade pip \
&& pip3 install --default-timeout=100 --no-cache-dir --upgrade setuptools \
&& if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi \
&& if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi \
&& rm -rf /var/cache/apk/* \
&& rm -rf ~/.cache/pip
# 设置 语言支持
ENV LANG=C.UTF-8
# 配置 应用工作目录
WORKDIR /data/apps/appdir
# 增加 项目文件
ADD appmain.py ./
ADD 你的py文件2.py ./
ADD 目录1 ./
ADD requirements.txt ./
# 安装 项目依赖包
RUN pip install -r requirements.txt
# 配置 对外端口
EXPOSE 11000
# 设置启动时预期的命令参数, 可以被 docker run 的参数覆盖掉.
CMD ["python", "appmain.py"]