Can you run GUI applications in a Docker container?

前端 未结 22 2510
南旧
南旧 2020-11-22 06:12

How can you run GUI applications in a Docker container?

Are there any images that set up vncserver or something so that you can - for example - add an e

22条回答
  •  别那么骄傲
    2020-11-22 06:47

    I managed to run a video stream from an USB camera using opencv in docker by following these steps:

    1. Let docker access the X server

      xhost +local:docker
      
    2. Create the X11 Unix socket and the X authentication file

      XSOCK=/tmp/.X11-unix
      XAUTH=/tmp/.docker.xauth
      
    3. Add proper permissions

      xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
      
    4. Set the Qt rendering speed to "native", so it doesn't bypass the X11 rendering engine

      export QT_GRAPHICSSYSTEM=native
      
    5. Tell Qt to not use MIT-SHM (shared memory) - that way it should be also safer security-wise

      export QT_X11_NO_MITSHM=1
      
    6. Update the docker run command

      docker run -it \
                 -e DISPLAY=$DISPLAY \
                 -e XAUTHORITY=$XAUTH \
                 -v $XSOCK:$XSOCK \
                 -v $XAUTH:$XAUTH \
                 --runtime=nvidia \
                 --device=/dev/video0:/dev/video0 \
                 nvcr.io/nvidia/pytorch:19.10-py3
      

    Note: When you finish the the project, return the access controls at their default value - xhost -local:docker

    More details: Using GUI's with Docker

    Credit: Real-time and video processing object detection using Tensorflow, OpenCV and Docker

提交回复
热议问题