我想在 docker 中部署我的 python 项目,我在 requirements.txt 中写了 lxml>=3.5.0
因为项目需要 lxml。这是我的码头文件:
FROM gliderlabs/alpine:3.3
RUN set -x \
&& buildDeps='\
python-dev \
py-pip \
build-base \
' \
&& apk --update add python py-lxml $buildDeps \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /app
ENV INSTALL_PATH /app
WORKDIR $INSTALL_PATH
COPY requirements-docker.txt ./
RUN pip install -r requirements.txt
COPY . .
RUN apk del --purge $buildDeps
ENTRYPOINT ["celery", "-A", "tasks", "worker", "-l", "info", "-B"]
当我将它部署到 docker 时,我得到了这个:
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1
----------------------------------------
Rolling back uninstall of lxml
我虽然是因为“python-dev”和“python-lxml”,但我还是像这样编辑了 dockfile:
WORKDIR $INSTALL_PATH
COPY requirements-docker.txt ./
RUN apt-get build-dev python-lxml
RUN pip install -r requirements.txt
它没有用,我得到了另一个错误:
---> Running in 73201a0dcd59
/bin/sh: apt-get: not found
如何在 docker 中正确安装 lxml?
原文由 thiiiiiking 发布,翻译遵循 CC BY-SA 4.0 许可协议
我在
RUN apk add --update --no-cache g++ gcc libxslt-dev
之前添加了 ---RUN pip install -r requirements.txt
并且它有效。