Reputation: 53
I am trying to create a docker image with opencv in order to display a video. I have the following Dockerfile:
FROM python:3
ADD testDocker_1.py /
ADD video1.mp4 /
RUN pip install opencv-python
CMD [ "python", "./testDocker_1.py" ]
And the following python script:
import cv2
import os
if __name__ == '__main__':
file_path = './video1.mp4'
cap = cv2.VideoCapture(file_path)
ret, frame = cap.read()
while ret:
ret, frame = cap.read()
if ret:
cv2.imshow('Frame Docker', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
So first I build the Image:
$ sudo docker build -t test1 .
And the problem comes when I run the container:
$ sudo docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix test1
No protocol specified
: cannot connect to X server :1
Regards.
Upvotes: 2
Views: 7078
Reputation: 1176
Try this
xhost +
sudo docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix test1
Although it would solve this particular use case, but you need to make a note of the following:
Basically, the xhost + allows everybody to use your host x server;
A better and recommended solution is present here
Upvotes: 4