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

时间:2015-06-23 23:36:54

标签: python-2.7 docker python-ldap

我正在使用python 2.7的官方python docker镜像。我正在使用的应用程序需要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构建的。我更像是一个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基础图像中,我旋转一个容器并捣乱。我可以证明安装了repos(虽然我真的不知道这些是否有效)

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实际上并没有外部访问repos,而apt-cache搜索只返回已经isntalled的包。如何在容器内安装和/或重新配置以实际执行任何操作?

有没有更好的方法来获得使用官方python图像编译python-ldap所需的软件包?

2 个答案:

答案 0 :(得分:12)

在安装之前运行apt-get update应该完成这项工作:

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

答案 1 :(得分:2)

这对我来说同时适用于Python 3.4& Python 3.5:

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