在我的人偶项目中使用 Docker 后,它无法正常工作。给出错误
After using Docker in my puppeteer project it is not working. Giving error
最近我在我现有的 MERN 项目中使用 docker,使用 Puppeteer.It 抓取 数据工作正常,但一旦我使用 docker 它不工作。出现以下错误。
----------- Open the browser ------------
server | Could not create a browser instance => : Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT
server |
server |
server | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
server |
server | at onClose (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
server | at ChildProcess.<anonymous> (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:85)
server | at ChildProcess.emit (events.js:314:20)
server | at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
server | at onErrorNT (internal/child_process.js:468:16)
server | at processTicksAndRejections (internal/process/task_queues.js:80:21)
server | ----------- Open a new page ------------
server | Could not create a new page => : TypeError: Cannot read property 'newPage' of undefined
server | at startPage (/app/controller/helper/browserHelper.js:35:26)
server | at businessinsiderOld (/app/controller/businessinsider/old.js:13:16)
server | at processTicksAndRejections (internal/process/task_queues.js:93:5)
server | (node:33) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'goto' of undefined
server | at businessinsiderOld (/app/controller/businessinsider/old.js:16:14)
server | at processTicksAndRejections (internal/process/task_queues.js:93:5)
server | (node:33) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
server | (node:33) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这是我的服务器docker文件
FROM node:14.5.0
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm","start"]
我刚刚使用了以下代码并且有效,
FROM node:14.5.0
WORKDIR /app
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
# https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-unstable
RUN apt-get update
# for https
RUN apt-get install -yyq ca-certificates
# install libraries
RUN apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
# tools
RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils
# and fonts
RUN apt-get install -yyq fonts-liberation
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm","start"]
最近我在我现有的 MERN 项目中使用 docker,使用 Puppeteer.It 抓取 数据工作正常,但一旦我使用 docker 它不工作。出现以下错误。
----------- Open the browser ------------
server | Could not create a browser instance => : Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT
server |
server |
server | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
server |
server | at onClose (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
server | at ChildProcess.<anonymous> (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:85)
server | at ChildProcess.emit (events.js:314:20)
server | at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
server | at onErrorNT (internal/child_process.js:468:16)
server | at processTicksAndRejections (internal/process/task_queues.js:80:21)
server | ----------- Open a new page ------------
server | Could not create a new page => : TypeError: Cannot read property 'newPage' of undefined
server | at startPage (/app/controller/helper/browserHelper.js:35:26)
server | at businessinsiderOld (/app/controller/businessinsider/old.js:13:16)
server | at processTicksAndRejections (internal/process/task_queues.js:93:5)
server | (node:33) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'goto' of undefined
server | at businessinsiderOld (/app/controller/businessinsider/old.js:16:14)
server | at processTicksAndRejections (internal/process/task_queues.js:93:5)
server | (node:33) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
server | (node:33) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这是我的服务器docker文件
FROM node:14.5.0
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm","start"]
我刚刚使用了以下代码并且有效,
FROM node:14.5.0
WORKDIR /app
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
# https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-unstable
RUN apt-get update
# for https
RUN apt-get install -yyq ca-certificates
# install libraries
RUN apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
# tools
RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils
# and fonts
RUN apt-get install -yyq fonts-liberation
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 9000
CMD ["npm","start"]