如果你只需要在基于python:2.7-alpine的 Docker镜像上为python 2.7安装psycopg2,那么下面的Dockerfile代码对你来说很不错:
FROM python:2.7-alpine RUN apk update && \ apk add --virtual build-deps gcc python-dev musl-dev && \ apk add postgresql-dev RUN pip install psycopg2
编译/安装psycopg2之前的解释
libpq
是PostgreSQL的客户端库https://www.postgresql.org/docs/9.5/libpq.html
postgresql-dev
带有标题的包,用于链接库/二进制文件中的libpq,就像psycopg一样.
我在alpine 3.7中使用以下配置,我添加一些注释来解释它.
# Installing client libraries and any other package you need
RUN apk update && apk add libpq
# Installing build dependencies
# For python3 you need to add python3-dev *please upvote the comment
# of @its30 below if you use this*
RUN apk add --virtual .build-deps gcc python-dev musl-dev postgresql-dev
# Installing and build python module
RUN pip install psycopg2
# Delete build dependencies
RUN apk del .build-deps
我无法安装它python:2.7.13-alpine
.结束了这个:
FROM gliderlabs/alpine:3.3 RUN apk add --no-cache --update \ python \ python-dev \ py-pip \ build-base RUN apk add --virtual build-deps gcc python-dev musl-dev && \ apk add --no-cache --update postgresql-dev && \ pip install psycopg2==2.7.1