Puppeteer with Firefox 在 Windows 上本地运行,但在 docker 容器上运行无效
Puppeter with Firefox works locally on Windows, but doesnt work on docker container
我有一个在 windows 上本地运行 nodejs 的项目没有问题。 firefox 是从 node_modules/puppeteer/.local-firefox
中的 npm install puppeteer@latest 自动下载的
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
product: 'firefox',
headless: true,
defaultViewport: {
width: 3544,
height: 3544,
},
});
问题是当我尝试在 docker 上做同样的事情时。
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
product: 'firefox',
headless: true,
defaultViewport: {
width: pageSizePx.width,
height: pageSizePx.height,
},
});
这就是 docker linux 的结果。
安装正常,firefox在原处。 node_modules/puppeteer/.local-firefox
Docker File
# base image
FROM node:12.15-alpine
# ENV CHROME_BIN="/usr/bin/chromium-browser"\
# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
##########
## Update and Install packages
##########
RUN set -x \
&& apk update \
&& apk upgrade \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
# add the packages
## g++: used to install NodeJS related packages
## chromium: used to run Puppeteer
&& apk add --no-cache g++ firefox
WORKDIR /scripts
WORKDIR /app
RUN apk add --no-cache curl bash
#RUN npm install -g ts
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
为了使用firefox,我用了puppeter的另一个类似选项,库是剧作家。
我有一个在 windows 上本地运行 nodejs 的项目没有问题。 firefox 是从 node_modules/puppeteer/.local-firefox
中的 npm install puppeteer@latest 自动下载的const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
product: 'firefox',
headless: true,
defaultViewport: {
width: 3544,
height: 3544,
},
});
问题是当我尝试在 docker 上做同样的事情时。
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
product: 'firefox',
headless: true,
defaultViewport: {
width: pageSizePx.width,
height: pageSizePx.height,
},
});
这就是 docker linux 的结果。
安装正常,firefox在原处。 node_modules/puppeteer/.local-firefox
Docker File
# base image
FROM node:12.15-alpine
# ENV CHROME_BIN="/usr/bin/chromium-browser"\
# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
##########
## Update and Install packages
##########
RUN set -x \
&& apk update \
&& apk upgrade \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
# add the packages
## g++: used to install NodeJS related packages
## chromium: used to run Puppeteer
&& apk add --no-cache g++ firefox
WORKDIR /scripts
WORKDIR /app
RUN apk add --no-cache curl bash
#RUN npm install -g ts
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
为了使用firefox,我用了puppeter的另一个类似选项,库是剧作家。