Search code examples
dockerraspberry-piraspbianmpv

Docker container running python-mpv: Cannot open shared object file libmmal_core.so


On my Raspberry Pi 3 Model B, I'd like to run python-mpv inside a Docker container. My Docker version is 18.02.0-ce, build fc4de44. Both the Raspberry and the Docker container run "Raspbian Stretch". This is the Dockerfile:

FROM resin/rpi-raspbian:stretch

RUN apt-get update
RUN apt-get install -y python3-pip ipython3 mpv libmpv1 python3-setuptools vim git
RUN pip3 install --upgrade pip
RUN pip3 install python-mpv
CMD python3 -c "import mpv"

When trying to run this Container on my Raspberry (docker build -t mpv .; docker run -it mpv), I get this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/mpv.py", line 46, in <module>
    backend = CDLL(sofile)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libmmal_core.so: cannot open shared object file: No such file or directory

Since libmmal_core.so is available on the host, I tried to just use the host folder as a volume for the Docker container, without success:

ifischer@raspi:~/mpv_docker $ docker run -v /opt/vc/lib:/opt/vc/lib -it mpv_web python3 -c "import mpv"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/mpv.py", line 46, in <module>
    backend = CDLL(sofile)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libmmal_core.so: cannot open shared object file: No such file or directory

How can I fix my Docker container so it finds libmmal_core.so?


Solution

  • Besides mounting /opt/vc/lib as volume into the Docker container, I had to set the environment variable LD_LIBRARY_PATH inside my dockerfile to point to the volume to-be-mounted, so that python-mpv will find the shared object files:

    ENV LD_LIBRARY_PATH /opt/vc/lib
    

    This is how I run my Docker container with success:

    docker run -v /opt/vc/lib:/opt/vc/lib -it mpv