Skip to main content
Version: 24.38.0

Docker

Puppeteer 提供了一个 Docker 镜像,其中包含 Chrome for Testing 以及所需的依赖和预安装的 Puppeteer 版本。该镜像可通过 GitHub Container Registry 获取。最新的镜像标签为 latest,其他标签与 Puppeteer 版本相对应。例如,

🌐 Puppeteer offers a Docker image that includes Chrome for Testing along with the required dependencies and a pre-installed Puppeteer version. The image is available via the GitHub Container Registry. The latest image is tagged as latest and other tags match Puppeteer versions. For example,

docker pull ghcr.io/puppeteer/puppeteer:latest # pulls the latest
docker pull ghcr.io/puppeteer/puppeteer:16.1.0 # pulls the image that contains Puppeteer v16.1.0

该镜像用于在沙箱模式下运行浏览器,因此,运行该镜像需要 SYS_ADMIN 权限。

🌐 The image is meant for running the browser in sandbox mode and therefore, running the image requires the SYS_ADMIN capability.

用法

🌐 Usage

要直接使用 docker 镜像,请运行:

🌐 To use the docker image directly, run:

docker run -i --init --cap-add=SYS_ADMIN --rm ghcr.io/puppeteer/puppeteer:latest node -e "$(cat path/to/script.js)"

其中 path/to/script.js 是相对于你的工作目录的路径。请注意,由于浏览器运行在沙箱模式下,该镜像需要 SYS_ADMIN 能力。

🌐 where path/to/script.js is the path relative to your working directory. Note the image requires the SYS_ADMIN capability since the browser runs in sandbox mode.

如果你需要基于不同的基础镜像构建镜像,你可以使用我们的 Dockerfile 作为起点。

🌐 If you need to build an image based on a different base image, you can use our Dockerfile as the starting point.

caution

请确保通过 --init 标志或自定义 ENTRYPOINT 指定一个初始化进程,以确保 Puppeteer 启动的所有进程都得到正确管理。

🌐 Make sure to specify a init process via the --init flag or a custom ENTRYPOINT to make sure all processes started by Puppeteer are managed properly.

dbus

该镜像为 Chrome 安装并配置了 dbus。通常在无头模式下你不需要 dbus,但你可能会在浏览器控制台看到警告。你可以在启动应用之前启动 dbus 服务:

🌐 The image installs and configures dbus for Chrome. Usually you would not need dbus in the headless mode but you might see warnings in the browser console. You can start the dbus service before launching your application:

sudo service dbus start

请参阅 https://docs.docker.com/config/containers/multi-service_container/ 获取关于如何在容器中启动多个进程的说明。

🌐 See https://docs.docker.com/config/containers/multi-service_container/ for instructions how to start multiple processes in a container.