简体   繁体   English

在外部Docker映像中构建python的gevent

[英]Build python's gevent in outer Docker image

This dockerfile will obviously not work: 该dockerfile显然将不起作用:

FROM python:3.7.0-alpine

RUN pip install gevent

since there is no compiler in alpine. 因为高山没有编译器。

Is it possible to install it in a different docker image and then copy it to my image? 是否可以将其安装在其他docker映像中,然后将其复制到我的映像中?

In other words, can i achieve that by replacing <???> with something? 换句话说,我可以通过将<???>替换为某些内容来实现吗?

FROM python:3.7.0-streach as base

RUN pip install gevent

FROM python:3.7.0-alpine

COPY --from=base <???>

For those finding this a year later, this should work: 对于一年后发现此问题的人,这应该起作用:

FROM python:3.7.0-stretch as base

RUN apk add build-base
RUN mkdir /install
RUN pip install --install-option="--prefix=/install" gevent

FROM python:3.7.0-alpine

COPY --from=base /install /usr/local

Alpine Linux has the build-base that provides a convenient way to install a compiler and other build tools. Alpine Linux具有build-base ,它提供了一种方便的方式来安装编译器和其他构建工具。 You'll want to install libffi-dev and other packages that provide headers as well. 您将要安装libffi-dev和其他提供标头的软件包。

Your intended approach to copy gevent from a Debian-based container to an Alpine-based one, will not work as the latter uses musl , not libc . gevent从基于Debian的容器复制到基于Alpine的容器的预期方法将不起作用,因为后者使用musl而非libc Have a look at apk 's --virtual option to easily un-/install build dependencies. 看一下apk--virtual选项可以轻松地--virtual /安装构建依赖项。

As far as I can tell, due to ABI changes gevent (or certain versions of it) do not compile against CPython 3.7 (yet). 据我所知,由于ABI的变化, gevent (或其某些版本)尚未针对CPython 3.7进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM