产生 Xvfb 的问题,服务器已经 运行

problem in spawning Xvfb, server already running

我正在尝试 运行 2 cypress docker 容器并行使用节点 js spawn

docker run -v path/to/ws:/e2e -w /e2e --network host cypress/included:8.0.0 --spec 'cypress/integration/cytorus-cache/1.feature'

docker run -v path/to/ws:/e2e -w /e2e --network host cypress/included:8.0.0 --spec 'cypress/integration/cytorus-cache/2.feature'

失败并出现以下错误;

Xvfb exited with a non zero exit code.

There was a problem spawning Xvfb.

This is likely a problem with your system, permissions, or installation of Xvfb.

----------

Error: _XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed

_XSERVTransMakeAllCOTSServerListeners: server already running
(EE)
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)

所以基本上,如果我 运行 4 个并行进程,其中 1 个连接到 X11 服务器,3 个出错。

如何处理?默认情况下,我已经尝试在无头模式下将 unset DISPLAY 设置为 Cypress 运行s。但是没有用。

我在 运行 并行测试 cypress 时遇到了同样的问题。 我的解决方法是从您的命令中删除 --network host 以避免端口冲突。您可能需要找到另一种方法来访问主机上的服务。

例如,您可以使用 172.17.0.1 访问 Docker 上的主机 Linux。

根据cypress docker documentation,

When running on Linux, Cypress needs an X11 server; otherwise it spawns its own X11 server during the test run. When running several Cypress instances in parallel, the spawning of multiple X11 servers at once can cause problems for some of them. In this case, you can separately start a single X11 server and pass the server's address to each Cypress instance using DISPLAY variable.

由于X11服务器已经运行在服务器上了,所以我刚生成Xvfb :99 &,然后设置地址export DISPLAY=:99。并将 DISPLAY 环境变量传递给 docker cypress 容器。