Skip to content

fix(docker): 修复容器中 Playwright 浏览器路径与权限不一致导致启动失败#373

Merged
dingyufei615 merged 1 commit intomasterfrom
codex/github-mention-docker-browsertype.launch-executa
Mar 6, 2026
Merged

fix(docker): 修复容器中 Playwright 浏览器路径与权限不一致导致启动失败#373
dingyufei615 merged 1 commit intomasterfrom
codex/github-mention-docker-browsertype.launch-executa

Conversation

@dingyufei615
Copy link
Collaborator

Motivation

  • 日志显示容器运行时无法找到 Playwright Chromium 可执行文件,错误为 BrowserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/...,其根因是构建期/运行期浏览器缓存路径与运行用户不一致且运行镜像未确保浏览器二进制可用。
  • 目标是确保运行镜像内存在与当前 Playwright 匹配的 Chromium 可执行文件,并且运行用户 appuser 可访问,避免启动失败与版本漂移问题。

Description

  • 将环境变量 PLAYWRIGHT_BROWSERS_PATH 改为固定全局路径 /ms-playwright,避免依赖 /root 或其它用户主目录。
  • 在最终运行镜像阶段执行 playwright install chromium,确保浏览器二进制在运行层被安装并与 Playwright 版本匹配。
  • 移除从 builder 阶段复制 /root/.cache/ms-playwright 的操作,改为在运行镜像中本地安装浏览器并对 /ms-playwright 目录执行 chown 使 appuser 可读写。
  • 保留将虚拟环境复制到运行镜像以确保 playwright CLI 可用并维持原有运行时结构。

Testing

  • 运行代码扫描与文件检查(例如 rg -n "playwright|BrowserType.launch|chromium|ms-playwright|install" 与查看 Dockerfile/src/scraper.py),确认引用点与修复位置,检查通过。
  • 尝试运行 docker compose -f docker-compose.dev.yaml config 以验证 compose 配置,但本环境没有 Docker CLI(command not found: docker),因此未能在本地构建或启动镜像。
  • 尝试访问外部 Playwright 文档以核对建议命令但请求被代理返回 403,无法在线验证浏览器安装细节;建议在 CI 或目标主机执行 docker compose build --no-cache appdocker compose up -d 并触发一次任务以完成端到端验证。

Codex Task

@dingyufei615 dingyufei615 merged commit 150af31 into master Mar 6, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决 Docker 容器中 Playwright 浏览器因路径不一致和权限不足而无法启动的问题。通过标准化 Playwright 浏览器的安装路径、确保在运行时环境中直接安装浏览器,并为非 root 用户 appuser 配置正确的目录权限,此更改显著提升了容器化 Playwright 应用的稳定性和可靠性,避免了启动失败和版本漂移。

Highlights

  • Playwright 浏览器路径配置: 将 Playwright 浏览器缓存路径 PLAYWRIGHT_BROWSERS_PATH 从用户主目录下的 /root/.cache/ms-playwright 更改为全局路径 /ms-playwright,以避免因用户差异导致的问题。
  • Playwright Chromium 安装策略: 移除了从构建阶段复制预安装浏览器的操作,改为在最终运行镜像阶段直接执行 playwright install chromium,确保浏览器与 Playwright 版本匹配并本地安装。
  • 用户权限管理: 更新了 chown 命令,将新定义的 Playwright 浏览器路径 /ms-playwright 的所有权授予非 root 用户 appuser,确保其具有访问和读写权限。
Changelog
  • Dockerfile
    • 更新了 PLAYWRIGHT_BROWSERS_PATH 环境变量的定义,指向新的全局路径。
    • 在最终镜像构建阶段添加了 playwright install chromium 命令,用于本地安装浏览器。
    • 移除了从 builder 阶段复制 Playwright 浏览器缓存的指令。
    • 修改了 chown 命令,将 /ms-playwright 目录的所有权授予 appuser
Activity
  • 作者执行了代码扫描与文件检查,确认引用点与修复位置,检查通过。
  • 作者尝试运行 docker compose -f docker-compose.dev.yaml config 验证配置,但因本地缺少 Docker CLI 而未能成功。
  • 作者尝试访问外部 Playwright 文档核对建议命令,但请求被代理返回 403,未能在线验证浏览器安装细节。
  • 作者建议在 CI 或目标主机上执行 docker compose build --no-cache appdocker compose up -d 并触发任务以进行端到端验证。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bca233e408

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

netcat-openbsd \
telnet \
&& playwright install-deps chromium \
&& playwright install chromium \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Eliminate duplicate Chromium download during docker build

Dockerfile now installs Chromium again in the runtime stage (playwright install chromium), while the builder stage still performs the same install (RUN playwright install chromium at line 25), so every image build downloads the browser twice. This significantly slows CI/build times and adds an unnecessary external network failure point without improving runtime correctness; keep only one install path (either reuse builder output or remove the builder install).

Useful? React with 👍 / 👎.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次变更旨在修复 Docker 容器中因 Playwright 浏览器路径与权限不一致导致的启动失败问题。您通过以下方式解决了此问题:

  1. 为 Playwright 浏览器设置了一个固定的、非用户主目录的路径 /ms-playwright
  2. 在最终镜像阶段直接安装浏览器及其依赖,而不是从构建器阶段复制。
  3. 为新的浏览器路径 /ms-playwright 设置了正确的用户权限,确保 appuser 可以访问。

这些改动逻辑清晰,有效地解决了描述的问题。我有一个小建议,即在 Dockerfile 中使用 --with-deps 标志来简化浏览器安装命令,将依赖安装和浏览器下载合并为一步。总体而言,这是一次不错的修复。

Comment on lines 58 to +59
&& playwright install-deps chromium \
&& playwright install chromium \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了简化命令并遵循 Playwright 的推荐做法,可以将 playwright install-deps chromiumplaywright install chromium 合并为一条命令。使用 playwright install --with-deps chromium 会同时安装浏览器及其操作系统依赖,使 Dockerfile 更简洁。

    && playwright install --with-deps chromium \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant