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

标签 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 构建的。我更像是一个红帽人,但我知道 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

好的,我认为 repos 丢失了,我做了更多研究,然后回到 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 search 只返回已经安装的包。我如何才能在容器中安装东西和/或重新配置它以实际执行任何操作?

有没有更好的方法来获取我需要用官方python镜像编译python-ldap的包?

最佳答案

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

运行 apt-get update && apt-get install -y libldap2-dev

关于python-2.7 - 以官方 python docker 镜像为基础运行 python-ldap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31015247/

相关文章:

eclipse - 如何在 mac osx 上完全卸载 eclipse che?

ruby-on-rails - Rails + Docker : ffi gem update today broke deploy?

django - python_ldap |在变量中提供证书内容

python - 我应该如何转义 ldap 特殊字符?

ldap - 如何在 python-ldap 中根据 dn 搜索 LDAP 中的对象?

python - 使用 pywin32(win32evtlog 模块)在 Python 中读取 Windows 事件日志

Python排序方法将两位数字字符串视为三位数字字符串

python - Django 从社交账户邀请好友

docker 容器中的 Laravel - 可以进行迁移但不能迁移

python - 在 scikit-learn 中运行 Randomforest 的 MemoryError