我正在尝试从Docker容器运行一个应用程序,该容器应该打开GUI寡妇(在我的情况下为视频流)。 Docker容器在Raspberry Pi上运行,我从Mac SSH进入Pi,然后发出Docker run命令。我这里有一个问题:
当我按如下方式运行整个程序时,它可以正常工作:
docker run -it --net = host --device = / dev / vcsm --device = / dev / vchiq -e 显示-v /tmp/.X11-unix joesan / motion_detector bash
从发出Docker run命令后打开的bash中,我安装了xauth
root @ cctv:/ raspi_motion_detection / project#apt-get install xauth
然后我使用Xauth add添加Xauth cookie
然后我运行我的Python程序,该程序显示带有视频流的GUI窗口
到目前为止,一切都很好。但是,每次我不想重复执行这些步骤时。所以我写了一个小脚本来做到这一点,如下所示:
HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
echo $DISPLAY_NUMBER
# Extract auth cookie
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:${DISPLAY_NUMBER} " | awk '{print $3}')
# Add the xauth cookie to xauth
xauth add ${HOHOSTSTNAME}/unix:${DISPLAY_NUMBER} MIT-MAGIC-COOKIE-1 ${AUTH_COOKIE}
# Launch the container
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector
但是这次失败并显示错误:
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused
然后我尝试以sudo用户身份运行上述脚本,并得到以下信息:
xauth: file /root/.Xauthority does not exist
xauth: (argv):1: bad "add" command line
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused
有什么我想念的吗?请帮忙!