可以跑 Puppeteer 的 Dockerfile 設定

研究了很久,遇到各種問題後可正常運作的版本:

FROM node:22-slim

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 \
    && apt-get install -y --no-install-recommends fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros \
      fonts-kacst fonts-freefont-ttf dbus dbus-x11 \
    && rm -rf /var/lib/apt/lists/*

ENV APP_ROOT=/app
ENV DBUS_SESSION_BUS_ADDRESS=autolaunch:
ENV PUPPETEER_SKIP_DOWNLOAD=true

WORKDIR ${APP_ROOT}

COPY . ${APP_ROOT}

RUN groupadd -r pptruser && useradd -u 10042 -rm -g pptruser -G audio,video pptruser
RUN chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser ${APP_ROOT}
USER pptruser

RUN npm i

ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome

CMD ["npm", "start"]