1

在Docker中使用python-ldap

 3 years ago
source link: https://note.qidong.name/2017/06/28/python-ldap-in-docker/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在Docker中使用python-ldap

2017-06-28 11:28:53 +08  字数:667  标签: Python LDAP Docker

本文介绍如何在Docker镜像python:alpine中安装python-ldap模块,并且尽量保持镜像的身材。

简介

python-ldap是一个Python的第三方库,包装了OpenLDAP的客户端,提供了面向对象的LDAP访问功能。 目前,它只支持Python 2.x

和其它Python包一样,它的安装命令很简单。

pip install python-ldap

然而, 在比较干净的环境下——比如Docker——安装时,会出现错误。 主要原因是,这并非一个纯粹的Python包,而是包含了C语言的内容。 安装时,会自动开始编译,需要安装环境自备编译依赖。

编译依赖

运行依赖

  • ldap, ldap_r The LDAP protocol library of OpenLDAP. ldap_r is the reentrant version and should be preferred.
  • lber The BER encoder/decoder library of OpenLDAP.
  • sasl2 The Cyrus-SASL library if needed and present during build
  • ssl The SSL/TLS library of OpenSSL if needed and present during build
  • crypto The basic cryptographic library of OpenSSL if needed and present during build

Dockerfile(部分)

FROM python:2.7.13-alpine

MAINTAINER "Yan QiDong <[email protected]>"

RUN apk update && apk add \
        libldap \
        gcc \
        libc-dev \
        python-dev \
        openldap-dev \
    && pip install --no-cache-dir python-ldap \
    && apk del \
        gcc \
        libc-dev \
        python-dev \
        openldap-dev \
    && rm -rf /tmp/*

说明

FROM python:2.7.13-alpine

基于python:2.7.13-alpine镜像。

其中,镜像自带libcrypto1.0与libssl1.0。 在安装libldap时会自动安装libsasl,这样运行环境就齐备了。

安装前,需要准备编译环境,即gcc、libc-dev、python-dev与openldap-dev。 安装后,这些运行时非必须的模块,都可以删除。

总结

如果是用基于Debian的python:2.7.13来做,会简单很多。 只是镜像也会大很多,python:2.7.13光自身就近700MB了。



本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可,详见本站版权声明

本站没有任何支持评论功能的计划。 如果你对本站的设计、内容、观点有什么意见,欢迎来信指正。


作者:匿蟒 邮箱:[email protected] 备案:闽ICP备15022549号


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK