You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu20.04 Docker中运行Cypress+Chrome报dri3不支持错误求助

问题描述

在Ubuntu 20.04 Docker容器内执行命令:

npx cypress run 'path/to/file.js' --browser chrome

出现错误提示:

ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported

当前安装Chrome及Cypress依赖的步骤如下:

# Install chromium
RUN apt install chromium-browser -y

RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install

## Cypress
RUN apt-get update && apt-get install -y 
RUN apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
解决方法
  • 给Chrome添加禁用GPU相关启动参数
    该错误源于Chrome尝试启用GPU加速,但Docker容器环境不支持DRI3扩展。直接禁用GPU相关功能即可解决,修改Cypress运行命令:

    npx cypress run 'path/to/file.js' --browser chrome -- --disable-gpu --disable-dev-shm-usage --no-sandbox
    

    也可以在Cypress配置文件(cypress.config.js)中全局配置Chrome参数,避免每次命令重复输入:

    module.exports = defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          // 其他配置
        },
      },
      browsers: [
        {
          name: 'chrome',
          channel: 'stable',
          args: ['--disable-gpu', '--disable-dev-shm-usage', '--no-sandbox']
        }
      ]
    });
    
  • 确保XVFB正确启动
    虽然已安装xvfb,但容器启动时可能未自动运行该服务。可以在执行Cypress命令前先启动XVFB:

    xvfb-run -a npx cypress run 'path/to/file.js' --browser chrome
    

    也可以在Dockerfile中添加启动脚本,保证容器启动时自动拉起XVFB。

  • 改用Chromium并配置参数
    既然已安装Chromium,也可以直接用它运行Cypress,同样加上禁用GPU的参数:

    npx cypress run 'path/to/file.js' --browser chromium -- --disable-gpu --no-sandbox
    

内容的提问来源于stack exchange,提问作者wonderfulworldwithcharity

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 14:20:27