Docker容器:ImportError: libGL.so.1: 无法打开共享对象文件:没有此文件或目录

-1 投票
1 回答
75 浏览
提问于 2025-04-13 21:29

我有一个深度学习项目,使用的是flask框架。我想把它放到docker容器里,但当我启动容器时,网页上显示了这个错误:

内部服务器错误 服务器遇到了内部错误,无法完成你的请求。可能是服务器负载过重,或者应用程序出现了错误。

这是容器的日志:

2024-03-18 11:55:14 [2024-03-18 10:55:14,583] ERROR in app: Exception on / [GET]
2024-03-18 11:55:14 Traceback (most recent call last):
2024-03-18 11:55:14   File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1463, in wsgi_app
2024-03-18 11:55:14     response = self.full_dispatch_request()
2024-03-18 11:55:14                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-18 11:55:14   File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 872, in full_dispatch_request
2024-03-18 11:55:14     rv = self.handle_user_exception(e)
2024-03-18 11:55:14          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-18 11:55:14   File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 870, in full_dispatch_request
2024-03-18 11:55:14     rv = self.dispatch_request()
2024-03-18 11:55:14          ^^^^^^^^^^^^^^^^^^^^^^^
2024-03-18 11:55:14   File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 855, in dispatch_request
2024-03-18 11:55:14     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
2024-03-18 11:55:14            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-03-18 11:55:14   File "/app/process/app.py", line 20, in capture_route
2024-03-18 11:55:14     capture_frame(path_name)
2024-03-18 11:55:14   File "/app/process/f_capture.py", line 4, in capture_frame
2024-03-18 11:55:14     import cv2
2024-03-18 11:55:14 ImportError: libGL.so.1: cannot open shared object file: No such file or directory
2024-03-18 11:55:14 172.17.0.1 - - [18/Mar/2024 10:55:14] "GET / HTTP/1.1" 500 

我有一个requirements.txt文件,里面列出了所有需要的包。

我尝试重新安装所有的包,但还是不行。

这是dockerfile:

# Use an official Python runtime as a parent image
FROM python:3.12.2

# Set the working directory in the container to /app
WORKDIR /app

# Install any needed packages specified in requirements.txt
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy the current directory contents into the container at /app
COPY . .

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Run the command to start your application
CMD cd process && flask run --host=0.0.0.0

1 个回答

0

解决办法是我在 requirements.txt 文件中添加了这个包:

opencv_python_headless

但是现在我遇到了一个相机错误:

[ WARN:0@0.008] global cap_v4l.cpp:997 open VIDEOIO(V4L2:/dev/video0): can't open camera by index
[ERROR:0@0.008] global obsensor_uvc_stream_channel.cpp:159 getStreamChannelGroup Camera index out of range

撰写回答