I have a deep learning project that uses flask . I want to put it in docker container but when I launch the container it display this error in web :
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
and this is the log of the container :
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
Keeping in mind I have a requirements.txt
file that has all package.
I tried re-installing all the packages but no luck.
this is the 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
The solution is i added this package to requirements.txt file :
opencv_python_headless
but now i have a camera error :
[ 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