项目作者: gergokee

项目描述 :
Install docker with Centos7 and Puppeteer on a Centos6 host machine.
高级语言: Dockerfile
项目地址: git://github.com/gergokee/centos6-puppeteer.git
创建时间: 2020-06-14T16:39:17Z
项目社区:https://github.com/gergokee/centos6-puppeteer

开源协议:MIT License

下载


Centos 6 puppeteer docker image

docker image with Google Puppeteer installed for Centos 6 only

If you can, please use Centos 7 or higher cause Centos 6 is EOL. Otherwise you can use this tool for Centos6.

Repo is based on Google Puppeteer and docker-puppeteer

before install

Make sure you upgraded your Centos 6 to latest:

  1. rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
  2. yum clean all && yum update
  3. reboot

After check version:

  1. cat /etc/redhat-release
  2. CentOS release 6.10 (Final)

Install Docker 1.7.1-1:

  1. yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm

Add docker to startup:

  1. chkconfig docker on

install

  1. docker pull gergokee/centos6-puppeteer:latest

before usage

  1. You should not pass --no-sandbox, --disable-setuid-sandbox args when launching it, only if there is no other way, when you need to run it as root (which is not recommended).
  1. const puppeteer = require('puppeteer');
  2. (async () => {
  3. console.info("Starting browser");
  4. let browser;
  5. try {
  6. browser = await puppeteer.launch({});
  7. } catch (e) {
  8. console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
  9. browser = await puppeteer.launch({args:[
  10. '--no-sandbox',
  11. '--disable-setuid-sandbox'
  12. ]});
  13. }
  14. console.info("Browser successfully started");
  15. console.info("Closing browser");
  16. await browser.close();
  17. console.info("Done");
  18. })();
  1. If you see errors like “ERR_NETWORK_CHANGED”, write your script to check the output of it and make a loop till the output is not generating errors. Unfortunately the problem is that IPV6 needs to be turned off. And because latest docker for Centos 6 is docker v1.7, you are unable to pass the necessary flag: —sysctl net.ipv6.conf.all.disable_ipv6=1
  1. add --enable-logging for chrome debug logging http://www.chromium.org/for-testers/enable-logging
  1. const puppeteer = require('puppeteer');
  2. (async() => {
  3. const browser = await puppeteer.launch({args: [
  4. '--no-sandbox',
  5. '--disable-setuid-sandbox',
  6. // debug logging
  7. '--enable-logging', '--v=1'
  8. ]});
  9. (async () => {
  10. console.info("Starting browser");
  11. let browser;
  12. try {
  13. browser = await puppeteer.launch({args: [
  14. '--enable-logging', '--v=1'
  15. ]});
  16. } catch (e) {
  17. console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox.");
  18. browser = await puppeteer.launch({args:[
  19. '--no-sandbox',
  20. '--disable-setuid-sandbox',
  21. '--enable-logging', '--v=1'
  22. ]});
  23. }
  24. console.info("Browser successfully started");
  25. console.info("Closing browser");
  26. await browser.close();
  27. console.info("Done");
  28. })();

usage

mount your script to /app/index.js

  1. docker run --rm -v <path_to_script>:/app/index.js gergokee/centos6-puppeteer:latest

custom script from dir

  1. docker run --rm \
  2. -v <path_to_dir>:/app \
  3. gergokee/centos6-puppeteer:latest \
  4. node my_script.js