1

Environment

  • Host running Ubuntu 14.04.5 LTS
  • Docker version 17.09.0-ce, build afdb6d4
  • Chromium 62.0.3202.89
  • 2 webcams: /dev/video0, /dev/video1

Cameras

# v4l2-ctl --list-devices
Venus USB2.0 Camera (usb-0000:00:1a.0-1.2.2):
    /dev/video1

USB 2.0 Camera (usb-0000:00:1a.0-1.3):
    /dev/video0

I need to share the webcams on Ubuntu 14.04 host to the Ubuntu 16.04 docker container and be able to get the video streams (WebRTC getUserMedia) from each camera on each chromium instance respectively running on the host and the container.

To test the getUserMedia, I am browsing to https://www.onlinemictest.com/webcam-test/

How to reproduce

Dockerfile

Dockerfile 
FROM ubuntu:16.04

# Install chromium
RUN apt-get update \
    && apt-get install sudo chromium-browser alsa-base -y \
    && rm -rf /var/lib/apt/lists/*

# Create a normal user to run chromium as
RUN useradd --create-home browser \
    && adduser browser video \
    && adduser browser audio \
    && usermod -aG sudo browser
USER browser
WORKDIR /home/browser

CMD ["/usr/bin/chromium-browser"]

docker-compose up

$ more docker-compose.yml 
version: '3'
services:
  chromium:
    build:
      context: .
      dockerfile: Dockerfile
    image: ubuntu-cr:0.1

    privileged: true

    environment:
        DISPLAY: $DISPLAY
        XAUTHORITY: /.Xauthority

    volumes:
        - /tmp/.X11-unix:/tmp/.X11-unix
        - ~/.Xauthority:/.Xauthority:ro

1. Start Chromium in docker container

export DISPLAY=:0.0 
docker-compose up

images

docker images
REPOSITORY      TAG            IMAGE ID            CREATED             SIZE
ubuntu-cr       0.1            a61f5506b1f9        9 minutes ago       764MB
ubuntu          16.04          747cb2d60bbe        2 months ago        122MB
hello-world     latest         05a3bd381fc2        3 months ago        1.84kB

2. When Chromium open in the docker container, browse to https://www.onlinemictest.com/webcam-test/

Great! I can see the video stream from my camera!

3. Open a Chromium browser to the same URL on the host

:( I get the ERROR message

Camera not authorized. Please check your media permissions settings

I get the same error, if I start Chromium on host first and browse to the camera test page to get the video stream (getUserMedia). When in sequence I run the Chromium in the container, I get the same ERROR message, which corresponds to the NavigatorUserMediaError > TrackStartError.

I tried from the Chromium console

navigator.mediaDevices.getUserMedia({audio: true, video: true})

and it gave me a TrackStartError when cam test already running on the other Chromium instance.

Any pointers on how to configure my docker container to allow one cam to be assigned to the host while the other is dedicated to the docker container?

Interesting threads

  • NotReadableError: Failed to allocate videosource points that this may be happening because the camera is used by another application.

  • Interestingly, when I open 2 Chromium instances on the host (no container this time) pointing to the same camera test page (getUserMedia), it does manage to get the same video stream to the 2 Chromium instances. That's when I try to access from a container that it conflicts. It can play either one or the other, but not at the same time. So it could be something to configure on the docker container. Still try to understand why this is happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.