以Flask部署为例,采用supervisor+uwsgi方式部署

首先有个好消息:supervisor在2019年4月开始支持python3,安装:

pip3 install supervisor

centos

FROM docker.io/centos

MAINTAINER LLC

RUN yum -y install wget && yum clean all && \
    mkdir -p /etc/yum.repos.d/bak/ && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ && \
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo && \
    \
    yum makecache all && \
    yum -y install gcc make zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel && \
    \
    mkdir -p /opt/dist && cd /opt/dist && wget https://npm.taobao.org/mirrors/python/3.6.5/Python-3.6.5.tgz && \
    tar xf Python-3.6.5.tgz && cd Python-3.6.5 && \
    mkdir -p /opt/python3 && ./configure --prefix=/opt/python3 && make -j16 && make install && \
    \
    /opt/python3/bin/pip3 install supervisor flask uwsgi -i http://pypi.douban.com/simple --trusted-host pypi.douban.com && \
    \
    /opt/python3/bin/echo_supervisord_conf > /etc/supervisord.conf && \
    echo "[include]" >> /etc/supervisord.conf && \
    echo "files = /etc/supervisord.d/*.conf" >> /etc/supervisord.conf && \
    \
    yum clean all && \
    cd /tmp && rm -rf /opt/dist

ENTRYPOINT ["/opt/python3/bin/supervisord", "-n","-c", "/etc/supervisord.conf"]

alpine

FROM alpine:3.9

MAINTAINER LLC

RUN echo "http://mirrors.aliyun.com/alpine/v3.9/main/" > /etc/apk/repositories && \
    echo "http://mirrors.aliyun.com/alpine/v3.9/community/" >> /etc/apk/repositories && \
    \
    apk add --no-cache gcc python3 python3-dev linux-headers libc-dev && \
    apk add --no-cache bash bash-doc bash-completion && \
    \
    pip3 install supervisor flask uwsgi -i http://pypi.douban.com/simple --trusted-host pypi.douban.com && \
    \
    echo_supervisord_conf > /etc/supervisord.conf && \
    echo "[include]" >> /etc/supervisord.conf && \
    echo "files = /etc/supervisord.d/*.conf" >> /etc/supervisord.conf && \
    \
    rm -rf /var/cache/apk/* && \
    rm -rf ~/.cache/pip

ENTRYPOINT ["supervisord", "-n","-c", "/etc/supervisord.conf"]

结果对比

以alpine为基础镜像构建后的体积要小很多,构建速度也比较快 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐