我正在使用适用于 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 的包?