首页 文章

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

提问于
浏览
10

我正在使用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 回答

  • 2

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

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

  • 12

    这适用于Python 3.4和Python 3.5:

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

相关问题