Use Puphpeteer with Docker

About this article

Introduce Puphpeteer to an existing project

It is a memo for myself

work

in-container-terminal


$ composer require nesk/puphpeteer
$ npm install @nesk/puphpeteer puppeteer

Modify php.ini if moss in memory

php.ini


memory_limit=1G

Dockerfile


FROM php:7.4.1-fpm

#abridgement

#Install puppeteer
RUN apt-get install -y nodejs gconf-service 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 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils libgbm-dev wget
RUN npm install --global --unsafe-perm puppeteer

#Japanese font installation(If you do not enter this, the characters will be garbled on the Japanese site)
RUN apt-get install fonts-ipafont-gothic fonts-ipafont-mincho

#abridgement

Success if example.png is created by executing the following process

puppeteer


<?php

use Illuminate\Console\Command;
use Nesk\Puphpeteer\Puppeteer;

class Scraping
{

    public function main()
    {
        $puppeteer = new Puppeteer;
        $browser = $puppeteer->launch([
            'args' => ['--no-sandbox', '--disable-setuid-sandbox']
    	]);
        $page = $browser->newPage();
        $page->goto('https://example.com');
        $page->screenshot(['path' => 'example.png']);

        $browser->close();
    }
}

reference

https://qiita.com/HeRo/items/9be64b559692e12cc109

Recommended Posts

Use Puphpeteer with Docker
Use ngrok with Docker
Use GDAL with Python with Docker
[Docker] Use whenever with Docker + Rails
Why use orchestration tools with Docker
Use cuda11.0 with pytorch using Docker
[Rails] How to use rails console with docker
Use Symbolic Link with Docker multi-stage builds
Use ZStandard with .NET Core + Docker (Alpine)
Use ProGuard with Gradle
Launch MariaDB with Docker
Rails deploy with Docker
Explode Docker with WSL2
Why we use Docker
Use Amazon ECR Credential Helper with Docker Desktop
Use XVim2 with Xcode 12.0.1
Use CentOS with LXD
Operate Emby with Docker
Try WildFly with Docker
Run Payara with Docker
Use webmock with Rspec
[Docker] Connection with MySQL
Php settings with Docker
How to use docker compose with NVIDIA Jetson
Getting Started with Docker
Use WebJars with Gradle
How to use nginx-ingress-controller with Docker for Mac
Use jlink with gradle
Disposable PHP with Docker
Install Composer with Docker
Pytorch execution environment with Docker
Use Thymeleaf with Azure Functions
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code
Use pfx certificate with Okhttp3
Set up GitLab with docker
Use Bulk API with RestHighLevelClient
Use SDKMAN! With Git Bash
Run Rails whenever with docker
Get started with DynamoDB with docker
Docker autostart settings with wsl2
[Docker] Rails 5.2 environment construction with docker
Use multiple databases with Rails 6.0
Spring Boot starting with Docker
Build docker environment with WSL
Version control CocoaPods with Docker
Use Spring JDBC with Spring Boot
Web application built with docker (1)
I tried BIND with Docker
Use Ruby with Google Colab
Use SpatiaLite with Java / JDBC
Use log4j2 with YAML + Gradle
React environment construction with Docker
Build DynamoDB local with Docker
Using PlantUml with Honkit [Docker]
[PHP8] Install and use PECL YAML function (YAML parser) with Docker
Use docker's in-container shell with cygwin [docker exec -it bash]
How to use mysql with M1 mac Docker preview version
You are required to use winpty with docker exec [Windows]
Use PlantUML with Visual Studio Code