FROM python:3.6
ENV PYTHONUNBUFFERED 1
ENV APP /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir $APP
WORKDIR $APP
ADD requirements.txt .
RUN pip install -r requirements.txt
COPY . .
要求。txt包含所有项目要求,即numpy。
Step 6/15 : RUN pip install numpy==1.14.3
---> Running in 266a2132b078
Collecting numpy==1.14.3
Downloading https://files.pythonhosted.org/packages/b0/2b/497c2bb7c660b2606d4a96e2035e92554429e139c6c71cdff67af66b58d2/numpy-1.14.3.zip (4.9MB)
Building wheels for collected packages: numpy
Building wheel for numpy (setup.py): started
Building wheel for numpy (setup.py): still running...
Building wheel for numpy (setup.py): still running...
Edit:
在Skybunk
的评论和前往官方文档的建议之后,对我的其他一些调试,解决方案变得非常简单。感谢
Skybunk感谢您的所有荣耀。是的Solution:
使用高山并安装python安装软件包依赖项,在执行PIP安装要求之前升级PIP。
这是我编辑的Dockerfile-显然工作...
FROM python:3.6-alpine3.7
RUN apk add --no-cache --update \
python3 python3-dev gcc \
gfortran musl-dev \
libffi-dev openssl-dev
RUN pip install --upgrade pip
ENV PYTHONUNBUFFERED 1
ENV APP /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir $APP
WORKDIR $APP
ADD requirements.txt .
RUN pip install -r requirements.txt
COPY . .
要在此处使用numpy,我们首先要进入
官方文档以查找构建numpy所需的依赖项。 务必要安装这5个软件包 +它们的依赖项:
python3 -70mb
Python3 -dev -25Mb
GCC -70MB MUSL -DEV -10 MB(用于跟踪意外行为/调试)
a poc设置看起来像这样-
dockerfile:FROM gliderlabs/alpine
ADD repositories.txt /etc/apk/repositories
RUN apk add --no-cache --update \
python3 python3-dev gcc \
gfortran musl-dev
ADD requirements-pip.txt .
RUN pip3 install --upgrade pip setuptools && \
pip3 install -r requirements-pip.txt
ADD . /app
WORKDIR /app
ENV PYTHONPATH=/app/
ENTRYPOINT python3 testscript.py
http://dl-5.alpinelinux.org/alpine/v3.4/main
numpy
import numpy as np
def random_array(a, b):
return np.random.random((a, b))
a = random_array(2,2)
b = random_array(2,2)
print(np.dot(a,b))
要运行此 - 克隆
alpine,使用“ docker build -t gliderlabs/alpine”构建它。
建造并运行您的Dockerfile
docker build -t minidocker .
docker run minidocker
输出应该像this-
[[ 0.03573961 0.45351115]
[ 0.28302967 0.62914049]]
另一个方法是从python的“细长”分布(基于Debian)安装:
FROM python:slim
CMD pip install numpy
这将产生的图像比高山的图像较小:
FROM python:3-alpine3.9
RUN apk add --no-cache py3-numpy
187MB加上它为Slim提供更好的支持,是基于
whl
库(构建所有车轮的库),而Apline使用
从误差日志,似乎不是来自numpy。但是您可以在需求之前安装numpy.txt并验证它是否正常。
musl
build
apk add
run和test
FROM python:3.6
RUN pip install numpy==1.14.3
因此,您将在导入上看到没有错误。
或您可以尝试
docker build -t numpy .
作为高山软件包
docker run numpy bash -c "echo import numpy as np > test.py ; python test.py"
或最好发布要求。txt.
numpy
和熊猫在这个问题上遇到了很多麻烦。 我的要求。
我总是在尝试FROM python:3-alpine3.9
RUN apk add --no-cache py3-numpy
时得到这样的东西:
提出:和:
遵循该线程中的提示,我进行了一些调试,发现它实际上可以正常工作并构建了一个完美运行的容器:
FROM python:3.9-buster
,为PIP3安装PANDAS提供了特定的运行层解决了问题!