run python-ldap with official python docker image as base

只谈情不闲聊 提交于 2021-02-18 20:30:56

问题


I am using the official python docker image for python 2.7. The application I am working with requires pyhon-ldap.

My dockerfile looked like this:

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

Where python-ldap is in requirements.txt

Naturally I run into this:

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 

Which I know is from not having libldap2-dev and some other packages installed. So I do a bit of research and find the official python image is built off of debian jessy. I'm more of a redhat person, but I know about apt-get so I modify my docker file to below:

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/

And that errors out like below

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

Ok, I figure that the repos are missing, I do some more research and back in the python base image I spin a container and muck around. I can prove there are repos installed (although I honestly have no idea if these are valid)

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

I cant seem to quite nail down what is going on but it looks like apt doesn't actually have external access to repos and apt-cache search is only returning packages that are already isntalled. How do I get apt to install things inside a container and/or reconfigure it to actually do anything?

Is there a better way to get the packages I need to compile python-ldap with the official python image?


回答1:


Running apt-get update prior to install should do the job:

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




回答2:


This worked for me with both Python 3.4 & Python 3.5:

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


来源:https://stackoverflow.com/questions/31015247/run-python-ldap-with-official-python-docker-image-as-base

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!