The Dockerfile in the link you provided doesn't specify how opencv was installed, can you provide the Dockerfile you used? Or how you installed opencv?
VideoCapture(0) won't work if you install opencv via pip.
You're using --device=/dev/video0:/dev/video0
correctly.
EDIT: This thread is more than five years old. Perhaps things have changed, but I can confirm that installing opencv via pip works fine. I stumbled upon this thread because I was facing a similar issue where my app could not access the camera when running inside a docker container. In case my the issue was with the user account I was using to run the python application inside the docker. I had the following lines in my Dockerfile:
RUN adduser -u 5678 --disabled-password --gecos "" appuser && \
chown -R appuser /app
USER appuser
Adding appuser
to video
group as shown below fixed the issue:
RUN adduser -u 5678 --disabled-password --gecos "" appuser && \
adduser appuser video && \
chown -R appuser /app
USER appuser
By the way, there is no need for the --privileged
flag in this case. Keep in mind that my setup runs on devices running Ubuntu/Debian based linux OS.