Reputation: 335
i am trying to make a dockerfile to opencv social distance detection project as a requirement to school project
the problem that i had is to make docker run on GUI-based environment
somehow i managed to make it work on linux by adding the fellow line to the run command
-e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro
the full command
sudo docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro social-distance-detection -y https://youtu.be/hTUyzF4v9KA
but it did not work on windows
which command should i add to docker run so it can run on windows ? and by any chance is there a way to make it even work without adding any extra line ?
there is the Dockerfile
FROM ubuntu:20.04
FROM python:3.8
LABEL maintainer="muhammed akyuzlu ***@gmail.com"
ADD Social-distance-detection.py /
ADD coco.names /
ADD yolov4.cfg /
ADD yolov4.weights /
RUN apt-get update \
&& apt-get install -y \
python3-pyqt5 \
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config \
libswscale-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavformat-dev \
libpq-dev \
xserver-xephyr\
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update -y \
&& apt-get install python3-pip -y \
&& pip install pafy \
&& pip install numpy \
&& pip install youtube-dl \
&& pip install numpy \
&& pip install opencv-python
ENTRYPOINT ["python","./Social-distance-detection.py"]
it is my first time with Docker so you could find some nonsense lines :)
Upvotes: 5
Views: 3305
Reputation: 5063
First, clean up your Dockerfile. I would suggest:
FROM python:3.8
LABEL maintainer="muhammed akyuzlu ***@gmail.com"
COPY Social-distance-detection.py /
COPY coco.names /
COPY yolov4.cfg /
COPY yolov4.weights /
RUN apt-get update && \
apt-get -y install \
build-essential \
cmake \
git \
wget \
unzip \
yasm \
pkg-config \
libswscale-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavformat-dev \
libpq-dev \
xserver-xephyr && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir pafy \
numpy \
youtube-dl \
PyQt5 \
opencv-python
ENTRYPOINT [ "python" , "./Social-distance-detection.py" ]
I'm not going to repeat my comment to your question, but as for other changes - you should use COPY
, rather than ADD
, unless you need ADD-specific features. You should only run apt-get install
once, then clean up all temporary files and caches. You should run pip
with --no-cache-dir
switch to avoid creating unnecessary caches in the first place.
Now for your actual question. As @David Maze suggested you need to install X Window Server, then configure it to accept all connections and finally run:
docker run -e DISPLAY=192.168.1.68:0.0 social-distance-detection -y https://youtu.be/hTUyzF4v9KA
replacing 192.168.1.68
with your host's IP address.
The process is described in detail in this article.
Upvotes: 3