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
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运行失败,并显示错误
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
import matplotlib.pyplot as plt
使用
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
但是它对我不起作用。还查看了ImportError: libGL.so.1: cannot open shared object file: No such file or directory,但我没有Ubuntu作为基本映像,因此该安装对我来说不起作用,如答案中所列。
让我知道一种实现此目的的方法。
答案 0 :(得分:1)
通过对dockerfile进行以下更改,我能够使docker容器运行
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错误所需的行
RUN apt install libgl1-mesa-glx -y
RUN apt-get install 'ffmpeg'\
'libsm6'\
'libxext6' -y
在不更新ubuntu环境的情况下无法运行。此外,将Docker映像创建为非交互式可以帮助跳过任何交互式命令行输入