简体   繁体   English

Docker 容器中缺少 CV2

[英]Missing CV2 in Docker container

I've made the following Dockerfile to build a python application:我制作了以下Dockerfile来构建 python 应用程序:

FROM python:3.7

WORKDIR /app

# Install python dependencies
ADD requirements.txt /app/
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

# Copy sources
ADD . /app

# Run detection
CMD ["detect.py" ]
ENTRYPOINT ["python3"]

The requirements.txt file contains only a few dependencies, including opencv : requirements.txt文件仅包含一些依赖项,包括opencv

opencv-python
opencv-python-headless
filterpy==1.1.0
lap==0.4.0
paho-mqtt==1.5.1
numpy
Pillow

Building the Docker image works perfectly.构建 Docker 镜像效果很好。 When I try to run the image, I got the following error:当我尝试运行映像时,出现以下错误:

ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Traceback (most recent call last):
  File "detect.py", line 6, in <module>
    import cv2
  File "/usr/local/lib/python3.7/site-packages/cv2/__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Seems like the CV2 dependency is not satisfied.似乎不满足 CV2 依赖项。

Is there something I missed building the Dockerfile ?我错过了构建Dockerfile的东西吗?

I have tried to replace opencv-python-headless by python3-opencv but there is no matching distribution found.我试图用python3-opencv替换opencv-python-headless但没有找到匹配的分布。

libGL.so.1 could be found in libgl1 , so you could add next to Dockerfile : libGL.so.1可以在libgl1中找到,因此您可以在Dockerfile旁边添加:

RUN apt update; apt install -y libgl1

Typically, docker images may remove many libraries to make the size small, these dependencies most probably could be already installed in your host system.通常,docker images 可能会删除许多库以减小大小,这些依赖项很可能已经安装在您的主机系统中。

So, for me, I usually use dpkg -S in host system to find which package I needed, then install them in container:所以,对我来说,我通常在主机系统中使用dpkg -S来查找我需要的包,然后将它们安装在容器中:

shubuntu1@shubuntu1:~$ dpkg -S libGL.so.1
libgl1:amd64: /usr/lib/x86_64-linux-gnu/libGL.so.1
libgl1:amd64: /usr/lib/x86_64-linux-gnu/libGL.so.1.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM