做法
在程式碼中,使用 --no-sandbox
參數啟動瀏覽器。
1 2 3 4 5
| await puppeteer.launch({ args: [ '--no-sandbox' ], });
|
新增 Dockerfile
檔:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| FROM node:12-slim
WORKDIR /app
RUN apt-get update \ && apt-get install -y wget gnupg \ && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ && apt-get update \ && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/*
RUN npm i puppeteer
COPY . .
RUN npm i
CMD [ "node", "main.js" ]
|
新增 docker-compose.yaml
檔:
1 2 3 4 5 6 7 8
| version: "3"
services: app: container_name: lyricist-screenshot build: . ports: - "80:80"
|
啟動專案。
參考資料