1

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

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

I looked at answer import matplotlib.pyplot as plt, ImportError: libGL.so.1: cannot open shared object file: No such file or directory relating to it and replaced

import matplotlib.pyplot as plt

with

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

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.

Falcon
  • 250
  • 4
  • 15
  • For the [standard Docker Hub Python image](https://hub.docker.com/_/python/), the `python:` images are Debian-based and the `apt-get install` from the linked question should work. You'd need to explicitly select a `python:-alpine` image. – David Maze Sep 14 '20 at 17:33
  • /bin/sh: apt-get: not found The command '/bin/sh -c apt-get install 'ffmpeg' 'libsm6' 'libxext6' -y' returned a non-zero code: 127 is what i get when i use alpine based image or not – Falcon Sep 14 '20 at 17:39
  • The command '/bin/sh -c apt install libgl1-mesa-glx' returned a non-zero code: 1 same with other alternative as well. – Falcon Sep 14 '20 at 18:11

1 Answers1

4

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"]

The lines required for resolving the libGl error

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

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

Falcon
  • 250
  • 4
  • 15