【问题标题】:Cannot start multiple processes with X11 in docker无法在 docker 中使用 X11 启动多个进程
【发布时间】:2021-01-22 22:30:31
【问题描述】:

我有以下 Dockerfile

FROM debian:bullseye

RUN \
apt-get -qq update && \
apt-get -qq -y --no-install-recommends install gedit && \
apt-get -qq clean && \
rm -rf /var/lib/apt/lists/

并使用以下脚本在支持 X11 的容器中启动 bash:

XAUTH=$(mktemp -t docker-XXXXXXXX)
trap "rm $XAUTH" EXIT
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -

docker run --rm --init -it \
    -e DISPLAY=$DISPLAY \
    -e XAUTHORITY=/tmp/xauth \
    -v $XAUTH:/tmp/xauth:rw \
    -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
    -u $(id -u):$(id -g) \
    [image] \
    /bin/bash

在容器内我可以在后台启动gedit &。第一个进程启动,一切正常,但是,在第二次启动时 gedit 崩溃:

This probably reflects a bug in the program.
The error was 'BadAccess (attempt to access private resource denied)'.
  (Details: serial 717 error_code 10 request_code 130 (MIT-SHM) minor_code 1)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
Trace/breakpoint trap (core dumped)

gedit & 的后续调用不受影响;只有第二次调用失败。

我已经用xeyes 尝试了上述方法,这个程序似乎不受影响。

【问题讨论】:

    标签: docker x11


    【解决方案1】:

    我遇到了一个非常相似的问题,并通过this answer 解决了它。

    您可以设置the option --ipc=host 以使 docker 容器能够与主机进程通信并访问共享内存。
    启动图形应用程序的命令如下所示:
    docker run <strong>--ipc=host</strong> -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:freemat

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      相关资源
      最近更新 更多