M1 Pro系统Docker中Cypress启动失败(缺失dbus依赖)求助
在M1 Pro上Docker运行Cypress缺失dbus依赖的解决方法
问题场景
在M1 Pro系统上执行以下Docker命令运行Cypress时启动失败:
docker run --rm -e BASE_URL=http://host.docker.internal:3000/ -v $PWD:/e2e -w /e2e cypress/included:13.11.0
错误信息
[STARTED] Task without title. [FAILED] Cypress failed to start. [FAILED] [FAILED] This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies [FAILED] [FAILED] Please refer to the error below for more details. [FAILED] [FAILED] ---------- [FAILED] [FAILED] [13:0614/074836.944798:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory [FAILED] [FAILED] <--- Last few GCs --- [FAILED] [FAILED] [13:0x2c001a4000] 52 ms: Mark-Compact (reduce) 0.6 (1.9) -> 0.6 (1.4) MB, 0.58 / 0.00 ms (average mu = 0.242, current mu = 0.051) last resort; GC in old space requested [FAILED] [13:0x2c001a4000] 53 ms: Mark-Compact (reduce) 0.6 (1.4) -> 0.6 (1.4) MB, 0.64 / 0.00 ms (average mu = 0.141, current mu = 0.021) last resort; GC in old space requested [FAILED] [FAILED] [FAILED] <--- JS stacktrace --- [FAILED] [FAILED] [FAILED] # [FAILED] # Fatal JavaScript out of memory: CALL_AND_RETRY_LAST # [FAILED] [FAILED] ---------- [FAILED] [FAILED] Platform: linux-arm64 (Debian - 12.5) [FAILED] Cypress Version: 13.11.0 Cypress failed to start. This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies Please refer to the error below for more details. ---------- [13:0614/074836.944798:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory <--- Last few GCs --- [13:0x2c001a4000] 52 ms: Mark-Compact (reduce) 0.6 (1.9) -> 0.6 (1.4) MB, 0.58 / 0.00 ms (average mu = 0.242, current mu = 0.051) last resort; GC in old space requested [13:0x2c001a4000] 53 ms: Mark-Compact (reduce) 0.6 (1.4) -> 0.6 (1.4) MB, 0.64 / 0.00 ms (average mu = 0.141, current mu = 0.021) last resort; GC in old space requested <--- JS stacktrace --- # # Fatal JavaScript out of memory: CALL_AND_RETRY_LAST # ---------- Platform: linux-arm64 (Debian - 12.5) Cypress Version: 13.11.0
解决方法
方案1:使用预配置完整依赖的Cypress浏览器镜像
cypress/included镜像仅包含Cypress核心,缺少桌面环境依赖。改用cypress/browsers系列镜像,这类镜像预装了dbus、浏览器及所有必要依赖,适配arm64架构:
docker run --rm --shm-size=256m -e BASE_URL=http://host.docker.internal:3000/ -v $PWD:/e2e -w /e2e cypress/browsers:node20.11.0-chrome123-ff124-edge123 cypress run
添加--shm-size=256m参数解决共享内存不足导致的JS内存溢出问题。
方案2:自定义镜像安装dbus依赖
基于cypress/included镜像构建自定义镜像,手动安装dbus:
- 创建
Dockerfile:
FROM cypress/included:13.11.0 RUN apt-get update && apt-get install -y dbus && rm -rf /var/lib/apt/lists/*
- 构建镜像:
docker build -t my-cypress .
- 运行自定义镜像:
docker run --rm --shm-size=256m -e BASE_URL=http://host.docker.internal:3000/ -v $PWD:/e2e -w /e2e my-cypress
方案3:挂载主机dbus socket(临时应急)
将主机的dbus socket挂载到容器中,解决socket缺失问题(不推荐用于生产环境,可能存在权限冲突):
docker run --rm --shm-size=256m -e BASE_URL=http://host.docker.internal:3000/ -v $PWD:/e2e -w /e2e -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket cypress/included:13.11.0
内容的提问来源于stack exchange,提问作者Kocin
相关产品推荐
相关产品推荐

