以官方的python docker镜像为基础运行python-ldap

我正在使用python 2.7官方的Python泊坞窗图像。 我正在使用的应用程序需要pyhon-ldap。

我的dockerfile看起来像这样:

FROM python:2.7 ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt ADD . /code/ 

python-ldap在requirements.txt中

当然我碰到这个:

 In file included from Modules/LDAPObject.c:9:0: Modules/errors.h:8:18: fatal error: lber.h: No such file or directory #include "lber.h" ^ compilation terminated. error: command 'gcc' failed with exit status 

我知道从没有libldap2-dev和一些其他软件包安装。 所以我做了一些研究,发现官方的python镜像是由debian jessy构build的。 我更多的是一个redhat的人,但我知道apt-get,所以我修改我的docker文件如下:

 FROM python:2.7 RUN apt-get install -y libldap2-dev ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt ADD . /code/ 

那个错误就像下面一样

 Step 1 : RUN apt-get install -y libldap2-dev ---> Running in 2ca6155b606e Reading package lists... Building dependency tree... Reading state information... Package libldap2-dev is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'libldap2-dev' has no installation candidate 

好吧,我认为这个回购是不存在的,我做了一些更多的研究,并回到了python的基础图像中,我旋转了一个容器,把它弄糟了。 我可以certificate有回购安装(虽然我真的不知道这些是否有效)

 cat /etc/apt/sources.list deb http://httpredir.debian.org/debian jessie main deb http://httpredir.debian.org/debian jessie-updates main deb http://security.debian.org jessie/updates main 

我似乎不能完全确定发生了什么,但它看起来像实际上并没有外部访问回购和apt-cachesearch只返回已经isntalled的软件包。 我怎样才能在容器内部安装东西,并且/或者重新configuration它以实际执行任何操作?

有没有更好的方式来获得我需要用官方的Python图像编译python-ldap包?

在安装前运行apt-get update应该可以做到这一点:

RUN apt-get update && apt-get install -y libldap2-dev

这对Python 3.4和Python 3.5都适用:

 RUN apt-get update && apt-get install -y python-dev libldap2-dev libsasl2-dev libssl-dev