alpine集成pandas及numpy

2,727 阅读2分钟

alpine安装pandas慢,且不能从whl安装,只能编译安装,所以集成备用:

仅是主要代码,具体可以参考: github.com/jfloff/alpi…

运行docker build 的容器如果需通过代理上网,需在文件中需求访问网络的操作前添加命令行:

export http_proxy=http://16.15.0.1:9011

和:

export https_proxy=http://16.15.0.1:9011

FROM python:3.7-alpine

MAINTAINER liu8816 
#alpine安装pandas慢,且不能从whl安装,只能编译安装,所以集成备用:

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV BOTTLE_VER 0.12.18

ENV PYTHON_BUILD_PACKAGES="\
    # numpy 依赖 \
	python3-dev gcc g++ freetype-dev gfortran musl-dev libgcc libquadmath musl libgfortran lapack-dev \
	# pillow 依赖 \
	jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
	bzip2-dev \
	coreutils \
	dpkg-dev dpkg \
	expat-dev \
	findutils \
	gdbm-dev \
	libc-dev \
	libffi-dev \
	libnsl-dev \
	libtirpc-dev \
	linux-headers \
	make \
	ncurses-dev \
	libressl-dev \
	pax-utils \
	readline-dev \
	sqlite-dev \
	tk \
	util-linux-dev \
	xz-dev \
	git \
	postgresql-dev \
	freetds-dev \
  " 

#pip安装中如有错误按提示增加
#python-dev #python-dev (missing),可能已经存在,用apk update升级,还可能名称不一致python3-dev

#COPY entrypoint.sh /entrypoint.sh
#COPY requirements.txt /data/requirements.txt

#更新Alpine的软件源为国内(清华大学)的站点,因为从默认官源拉取实在太慢了。。。
# http://dl-cdn.alpinelinux.org/alpine/v3.11/main
# https://mirrors.aliyun.com/alpine/
#set是shell的一个命令,因为shell的执行的过程中,如果有某个出错了,也会继续往下执行,set -ex作用就是,当下面的命令执行出错后,就退出执行,不在继续往下执行。
#RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN set -ex \
    #容器通过代理上网时需开启 \
	&& export http_proxy=http://16.15.0.1:9011 \
	&& export https_proxy=http://16.15.0.1:9011 \
	
	&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
	&& pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
	&& pip config set install.trusted-host mirrors.aliyun.com \
	&& apk add --update --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES \
	#Cython 否则有的pip安装失败 \
	&& pip install Cython \
	&& pip install numpy \
	&& pip install matplotlib \
    #==3.2.1 #指定版本号可能需要先生成wheel,再安装,比较慢 \
	&& pip install pandas \
    && pip install pynacl \
    && pip install gevent \
    && pip install psycopg2-binary \
	&& pip install bottle==$BOTTLE_VER \
	&& pip install uwsgi \
    #其他不需要编译安装的可以统一放在一个requirements.txt文件中 \
	#&& pip install --no-cache-dir -r /data/requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
	&& apk del --no-cache --purge .build-deps
RUN rm -rf /var/cache/apk/*
EXPOSE 80
CMD /bin/sh

    # set proper permission to run entrypoint script
#chmod a+x /entrypoint.sh

# This script installs APK and Pip prerequisites on container start, or ONBUILD. Notes:
#   * Reads the -a flags and /apk-requirements.txt for install requests
#   * Reads the -b flags and /build-requirements.txt for build packages -- removed when build is complete
#   * Reads the -p flags and /requirements.txt for Pip packages
#   * Reads the -r flag to specify a different file path for /requirements.txt
#ENTRYPOINT ["/usr/bin/dumb-init", "bash", "/entrypoint.sh"]

运行时如有错误:

ERROR: mirrors.aliyun.com/alpine/v3.1… temporary error (try again later)

解决:

方法一、----------如果centos8不能解析域名:

#新增防火墙配置:

#firewall-cmd --zone=public --add-masquerade --permanent
#firewall-cmd --reload
#systemctl restart docker

方法二 、增加参数,通过本地的网络进行构建

docker build -t py37bottle:v1_pandas . --network=host

enterpiont.sh