Puppeteer在docker下踩坑记录

最近有需求要进行浏览器截图,就开始研究Puppeteer。因为项目是k8s的所有还是遇到了一些坑来做记录。

1.依赖

基础镜像缺少Chromium所需要的依赖,所有导致运行报错。

centos安装依赖

yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y

alpine安装依赖

# 设置阿里镜像源
echo "https://mirrors.aliyun.com/alpine/edge/main" > /etc/apk/repositories
echo "https://mirrors.aliyun.com/alpine/edge/community" >> /etc/apk/repositories
echo "https://mirrors.aliyun.com/alpine/edge/testing" >> /etc/apk/repositories

# 安装Chromium及依赖,包括中文字体支持
apk -U --no-cache update
apk -U --no-cache --allow-untrusted add zlib-dev xorg-server dbus ttf-freefont chromium wqy-zenhei@edge -f

  

2.时区问题

容器的时区一定要设置好,不然Chrome浏览器的时区也会跟着出问题。

因为暂时不太清楚怎么在Puppeteer中对Chrome设置时区,所有只能先在dockerfile中加入如下内容:

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone

参考文章 https://www.jianshu.com/p/6a07fbd5b299

猜你喜欢

转载自www.cnblogs.com/naocanzhishen/p/12221738.html