首页 > 解决方案 > 无法使用安装了 ubuntu、numpy、opencv 的方式编写 dockerfile

问题描述

该计划是部署预训练的人脸识别模型。但在我需要安装一些库之前。

docker 背后的想法是它带来了所有需要的库并构建整个“环境”而没有太多开销。只需启动 dockerfile,它就会依次运行所有其他脚本。

要安装的库:

我试图使用 curl 从 URL 下载 pkgs,但它不起作用。

我的码头文件:

FROM ubuntu:16.04.6

RUN apt-get update && apt-get install -y curl bzip2 
    curl -o numpy
    && sudo apt-get install numpy
    && curl install imutils https://github.com/jrosebr1/imutils
    && curl install dlib https://dlib.net
    && sudo git clone https://github.com/ageitgey/face_recognition.git
    && curl python-opencv https://opencv.org/
    && echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc \
    &&  ~/anaconda3/bin/conda update -n base conda \
    &&  rm miniconda_install.sh \
    &&  rm -rf /var/lib/apt/lists/* \
    &&  /bin/bash -c "source ~/.bashrc"

ENV PATH="~/anaconda3/bin:${PATH}"


##################################################
#    Setup env for current project:
##################################################

EXPOSE 8000

RUN /bin/bash -c "conda create -y -n PYMODEL3.6"

ADD requirements.txt /tmp/setup/requirements.txt

RUN /bin/bash -c "source activate PYMODEL3.6 && pip install -r /tmp/setup/requirements.txt"

WORKDIR /Service

ADD Service /Service

ENTRYPOINT ["/bin/bash", "-c", "source activate PYMODEL3.6 && ./run.sh"]

人脸模型是预训练的。有2个python文件进行实际检测、128d编码和识别。用法是这样的:

#detect face, if there is face - encode it, return pickle
python3 encode.py --dataset dataset_id --encodings encodings.pickle
--confidence 0.9

#recognize using pickle
python3 face_recognizer.py --encodings encodings.pickle --image
dataset_webcam/3_1.jpg --confidence 0.9 --tolerance 0.5

我应该将它们包含在 dockerfile 中吗?

标签: pythondockerdockerfile

解决方案


我建议您使用如下所示的 Dockerfile,假设您的 requirements.txt 文件中有所有要求(numpy、imutils 等),并且您的文件夹中有encode.py和文件:face_recognizer.pyService

FROM python:3.6.10

RUN mkdir /tmp/setup

ADD requirements.txt /tmp/setup/requirements.txt

RUN pip install --no-cache-dir --upgrade setuptools && \
    pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /tmp/setup/requirements.txt

WORKDIR /Service

ADD Service /Service/

CMD ["./run.sh"]

EXPOSE 8000

推荐阅读