由于libGl错误而无法运行Docker映像

由于libGl错误而无法运行Docker映像

本文介绍了由于libGl错误而无法运行Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dockerfile

Dockerfile

FROM python:3.6.8
COPY . /app
WORKDIR /app
RUN pip3 install --upgrade pip
RUN pip3 install opencv-python==4.3.0.38
RUN pip3 install -r requirements.txt
EXPOSE 80
CMD ["python3", "server.py"]

requirements.txt

requirements.txt

Flask==0.12
Werkzeug==0.16.1
boto3==1.14.40
torch
torchvision==0.7.0
numpy==1.15.4
sklearn==0.0
scipy==1.2.1
scikit-image==0.14.2
pandas==0.24.2

docker构建成功,但docker运行失败,并显示错误

The docker build succeeds but the docker run fails with the error

INFO:matplotlib.font_manager:Generating new fontManager, this may take some time...
PyTorch Version:  1.6.0
Torchvision Version:  0.7.0
Traceback (most recent call last):
  File "server.py", line 7, in <module>
    from pipeline_prediction.pipeline import ml_pipeline
  File "/app/pipeline_prediction/pipeline.py", line 3, in <module>
    from segmentation_color import get_swatch_color_from_segmentation
  File "pipeline_prediction/segmentation_color.py", line 7, in <module>
    import cv2
  File "/usr/local/lib/python3.6/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

我看着答案以plt格式导入matplotlib.pyplot,ImportError:libGL.so.1:无法打开共享库文件:没有与之相关的文件或目录并已被替换

import matplotlib.pyplot as plt

使用

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

但是它对我不起作用.还查看了 ImportError:libGL.so.1:无法打开共享对象文件:没有这样的文件或目录,但是我没有Ubuntu作为基本映像,因此该安装对我来说不起作用,如答案中所列.

but it is not working for me. Also looked at ImportError: libGL.so.1: cannot open shared object file: No such file or directory but I do not have Ubuntu as base image so this installation would not work for me as listed in the answer.

让我知道一种实现此目的的方法.

Let me know a way to make this work.

推荐答案

通过对dockerfile进行以下更改,我能够使docker容器运行

I was able to make the docker container run by making following changes to the dockerfile

FROM python:3.6.8
COPY . /app
WORKDIR /app
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y
RUN apt install libgl1-mesa-glx -y
RUN apt-get install 'ffmpeg'\
    'libsm6'\
    'libxext6'  -y
RUN pip3 install --upgrade pip

RUN pip3 install opencv-python==4.3.0.38
RUN pip3 install -r requirements.txt
EXPOSE 80
CMD ["python3", "server.py"]

解决libGl错误所需的行

The lines required for resolving the libGl error

RUN apt install libgl1-mesa-glx -y
RUN apt-get install 'ffmpeg'\
    'libsm6'\
    'libxext6'  -y

在不更新ubuntu环境的情况下无法运行.此外,将Docker映像创建为非交互式可以帮助跳过任何交互式命令行输入

were not able to run without updating the ubuntu environment. Moreover creating the docker image as noninteractive helped to skip any interactive command line inputs

这篇关于由于libGl错误而无法运行Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:04