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?
Running
apt-get update
prior to install should do the job:RUN apt-get update && apt-get install -y libldap2-dev