1

Reading the dockerfile presented in the docker folder.

FROM node:16

# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
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-khmeros fonts-kacst fonts-freefont-ttf libxss1 \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /home/pptruser

COPY puppeteer-latest.tgz /home/pptruser/puppeteer-latest.tgz

# Install puppeteer into /home/pptruser/node_modules.
RUN npm i ./puppeteer-latest.tgz \
    && rm puppeteer-latest.tgz \
    # Add user so we don't need --no-sandbox.
    # same layer as npm install to keep re-chowned files from using up several hundred MBs more space
    && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    && mkdir -p /home/pptruser/Downloads \
    && chown -R pptruser:pptruser /home/pptruser \
    && (node -e "require('child_process').execSync(require('puppeteer').executablePath() + ' --credits', {stdio: 'inherit'})" > THIRD_PARTY_NOTICES)

USER pptruser

CMD ["google-chrome-stable"]

I created the .tar file needed for the docker.

  • Git clone
  • npm install
  • npm pack, put the .tar created in the docker folder
  • renamed the .tar to be used by the dockerfile

It builds correctly. But why did they launch the chrome browser at the end with the CMD command? It is not needed to run puppeteer afterwards, is it ?

1 Answers1

0

Yes CMD ["google-chrome-stable"] is how puppeteer Dockerfile ends:

https://github.com/puppeteer/puppeteer/blob/main/docker/Dockerfile#L27

CMD is just default command for docker to run, if you do docker run, e.g.

docker run -i --init --rm ghcr.io/puppeteer/puppeteer:latest

By the way, it just fails as of 2023-04-25

Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
[0425/174930.230391:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0425/174930.230488:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)

But run any command, e.g. node to execute .js script :

docker run -i --init  --rm ghcr.io/puppeteer/puppeteer:latest node -e "$(cat puppeteerexample.js)"

From https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile#:~:text=Docker%20has%20a%20default%20entrypoint,is%20run%20via%20the%20entrypoint.

Docker has a default entrypoint which is /bin/sh -c but does not have a default command. When you run docker like this: docker run -i -t ubuntu bash the entrypoint is the default /bin/sh -c , the image is ubuntu and the command is bash . The command is run via the entrypoint.


And you don't need to git clone and build, just to use the docker image.

Paul Verest
  • 60,022
  • 51
  • 208
  • 332